diff --git a/.github/workflows/docker-build-publish.yml b/.github/workflows/docker-build-publish.yml new file mode 100644 index 0000000..e260718 --- /dev/null +++ b/.github/workflows/docker-build-publish.yml @@ -0,0 +1,54 @@ +name: Docker Build and Publish + +on: + push: + branches: [ "main" ] + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=latest,enable={{is_default_branch}} + type=sha,format=short + type=ref,event=branch + type=ref,event=tag + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + build-args: | + NEXT_TELEMETRY_DISABLED=1 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 02e5f05..b2cc90f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,9 +30,9 @@ COPY . . # ENV NEXT_TELEMETRY_DISABLED=1 RUN \ - if [ -f yarn.lock ]; then yarn run build; \ - elif [ -f package-lock.json ]; then npm run build; \ - elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \ + if [ -f yarn.lock ]; then yarn run build --no-lint; \ + elif [ -f package-lock.json ]; then npm run build --no-lint; \ + elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build --no-lint; \ else echo "Lockfile not found." && exit 1; \ fi diff --git a/README.md b/README.md index 17cd5de..c60caf6 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,57 @@ docker run -p 3000:3000 --env-file .env nextjs-gemini-image-editing Open [http://localhost:3000](http://localhost:3000) with your browser to see the application. +### GitHub Actions Automated Build + +This project is configured with GitHub Actions workflow to automatically build Docker images and publish them to GitHub Container Registry (GHCR). + +#### Triggers + +The workflow is triggered by: +- Push to the `main` branch +- Manual workflow dispatch + +#### Features + +1. Checkout repository code +2. Set up Docker Buildx +3. Log in to GitHub Container Registry +4. Extract Docker image metadata (tags, labels) +5. Build and push Docker image to GitHub Container Registry + +#### Image Tags + +Automatically generated tags include: +- `latest` (only for default branch) +- Short SHA commit hash +- Branch name +- Tag name (if any) + +#### Permissions + +The workflow requires the following permissions: +- `contents: read` - Read repository contents +- `packages: write` - Write to GitHub Packages (for publishing Docker images) + +#### Usage + +1. Ensure GitHub Actions is enabled for your repository +2. Ensure GitHub Packages is enabled for your repository +3. Push code to the `main` branch or manually trigger the workflow +4. After the build completes, view the published Docker image on the GitHub Packages page + +#### Pull Image + +```bash +docker pull ghcr.io/[username]/[repository]:latest +``` + +#### Run Container + +```bash +docker run -p 3000:3000 -e GEMINI_API_KEY=your_google_api_key ghcr.io/[username]/[repository]:latest +``` + ## Technologies Used - [Next.js](https://nextjs.org/) - React framework for the web application diff --git a/components/ImageResultDisplay.tsx b/components/ImageResultDisplay.tsx index 65a4982..fe51aee 100644 --- a/components/ImageResultDisplay.tsx +++ b/components/ImageResultDisplay.tsx @@ -57,6 +57,7 @@ export function ImageResultDisplay({