Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,73 @@ jobs:
cp docs/README_NPM.md app/README.md
cd app
npm publish --provenance --access public

docker-build-push:
name: Build and Push Docker Image
if: github.event.release.target_commitish == 'main' && vars.DOCKERHUB_USERNAME != ''
needs: [lint-test-app]
runs-on: ubuntu-latest
env:
REGISTRY: docker.io
IMAGE_NAME: weaponsforge/cloudinary-cli
permissions:
contents: read
security-events: write
packages: write
steps:
- name: Checkout the repository
uses: actions/checkout@v6
with:
ref: ${{ github.event.release.tag_name }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Generate Docker Image Tags and Labels
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
# type=semver,pattern={{major}}.{{minor}}
type=raw,value=latest,enable={{is_default_branch}}

- name: Build and Push Docker Image
id: build
uses: docker/build-push-action@v6
with:
context: ./app
file: ./app/Dockerfile
target: production
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
BUILDKIT_INLINE_CACHE=1
CACHEBUST=${{ github.run_id }}

- name: Scan Image for Vulnerabilities
uses: aquasecurity/trivy-action@v0.35.0
with:
image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build.outputs.digest }}
format: 'sarif'
output: 'trivy-results.sarif'

- name: Upload Trivy Scan Results to GitHub Security Tab
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: 'trivy-results.sarif'
35 changes: 29 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Create a `.env` file in the `/app` directory, replacing the contents of the `.en
| CLOUDINARY_NAME | Cloudinary account name |
| CLOUDINARY_API_KEY | Cloudinary API key |
| CLOUDINARY_API_SECRET | Cloudinary API secret |
| CHOKIDAR_USEPOLLING | Enables file watching on `tsx watch` running inside Docker containers on a Windows host. Set it to `true` if running Docker Desktop with WSL2 on a Windows OS host. |
| CHOKIDAR_INTERVAL | Chokidar polling interval. Set it along with `CHOKIDAR_USEPOLLING=true` if running Docker Desktop with WSL2 on a Windows OS host. The default value is `1000`. |

## Usage

Expand All @@ -29,9 +31,13 @@ Create a `.env` file in the `/app` directory, replacing the contents of the `.en
2. Run the container.<br>
`docker compose up`

3. Run the [Available Scripts](#available-scripts) using Docker.
3. Edit the `.ts` source files and watch for changes.

4. Run the [Available Scripts](#available-scripts) using Docker.

5. See the examples under the [Code Samples](#-code-samples) section for more information.


4. See the examples under the [Code Samples](#-code-samples) section for more information.

**Example using the development Docker image**

Expand All @@ -57,16 +63,24 @@ Build the production image with<br>

#### B. Using Node.js

1. Install dependencies.<br>
1. Install dependencies.

```sh
cd app
npm install
```

2. Run the [Available Scripts](#available-scripts).
2. Run the app in development mode.

```
npm run dev
```

3. See the examples under the [Code Samples](#-code-samples) section for more information.
3. Edit the `.ts` source files and watch for changes.

4. Run the [Available Scripts](#available-scripts).

5. See the examples under the [Code Samples](#-code-samples) section for more information.

## Available Scripts

Expand Down Expand Up @@ -100,7 +114,7 @@ npm start -- \

### `npm run dev`

Runs the `npm start` script in development mode with `tsx`.
Runs the `npm start` script in development mode with file watching using `tsx`.

Example usage:<br>
`npm run dev -- -f /assets/sunset.jpg -u`
Expand All @@ -127,6 +141,15 @@ Fixes lint errors in TypeScript files.

Watches file changes in `.ts` files using the `tsc --watch` option.

### `npm run docker:dev`

Docker counterpart of the `npm run dev` script. Exports the `IS_DOCKER=true` variable and runs the `npm run dev` script in development mode with file watching using `tsx` within Docker.

> [!TIP]
> Set `CHOKIDAR_USEPOLLING=true` and `CHOKIDAR_INTERVAL=1000` in the `.env` file to enable file watching on when running inside Docker containers on a Windows host.
>
> Uncomment and use ` _values` in **/src/scripts/optimize/index.ts** to manually set `optimize(_values)` not from CLI input.

### `npm run docker:watch:win`

Watches file changes in `.ts` files using the `tsc --watch` option with `dynamicPriorityPolling` in Docker containers running in Windows WSL2.
Expand Down
2 changes: 1 addition & 1 deletion app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RUN npm ci
COPY --chown=node:node . ./
USER node
EXPOSE 9229
CMD ["sh"]
CMD ["npm", "run", "docker:dev"]

# Proudction target profile
FROM base AS production
Expand Down
Loading
Loading