diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d0cef2d..f2e8f46 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -204,8 +204,8 @@ jobs: context: ./backend push: false tags: wardrowbe/backend:test - cache-from: type=gha - cache-to: type=gha,mode=max + cache-from: type=gha,scope=backend + cache-to: type=gha,mode=max,scope=backend - name: Build frontend image uses: docker/build-push-action@v7 @@ -213,5 +213,5 @@ jobs: context: ./frontend push: false tags: wardrowbe/frontend:test - cache-from: type=gha - cache-to: type=gha,mode=max + cache-from: type=gha,scope=frontend + cache-to: type=gha,mode=max,scope=frontend diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..8ed0c87 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,56 @@ +name: Docker Publish + +on: + push: + branches: [main] + release: + types: [published] + +env: + GHCR_REGISTRY: ghcr.io + +jobs: + publish: + name: Publish ${{ matrix.service }} + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + strategy: + fail-fast: false + matrix: + include: + - service: backend + context: ./backend + tag_prefix: backend + - service: frontend + context: ./frontend + tag_prefix: frontend + + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v4 + + - name: Lowercase image name + run: echo "GHCR_IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV + + - name: Login to GHCR + uses: docker/login-action@v3 + with: + registry: ${{ env.GHCR_REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v7 + with: + context: ${{ matrix.context }} + push: true + tags: | + ${{ env.GHCR_REGISTRY }}/${{ env.GHCR_IMAGE_NAME }}:${{ matrix.tag_prefix }}-latest + ${{ env.GHCR_REGISTRY }}/${{ env.GHCR_IMAGE_NAME }}:${{ matrix.tag_prefix }}-${{ github.sha }} + cache-from: type=gha,scope=${{ matrix.service }} + cache-to: type=gha,mode=max,scope=${{ matrix.service }} diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index f186ffd..0662633 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -38,9 +38,7 @@ services: # FastAPI Backend backend: - build: - context: ./backend - dockerfile: Dockerfile + image: ghcr.io/anyesh/wardrowbe:backend-latest container_name: wardrobe_backend restart: unless-stopped extra_hosts: @@ -91,9 +89,7 @@ services: # arq Worker for background jobs worker: - build: - context: ./backend - dockerfile: Dockerfile + image: ghcr.io/anyesh/wardrowbe:backend-latest container_name: wardrobe_worker restart: unless-stopped command: arq app.workers.worker.WorkerSettings @@ -130,11 +126,7 @@ services: # Next.js Frontend frontend: - build: - context: ./frontend - dockerfile: Dockerfile - args: - NEXT_PUBLIC_API_URL: "" + image: ghcr.io/anyesh/wardrowbe:frontend-latest container_name: wardrobe_frontend restart: unless-stopped extra_hosts: diff --git a/docker-compose.yml b/docker-compose.yml index 2525bf5..b9628b6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -35,9 +35,7 @@ services: # FastAPI Backend backend: - build: - context: ./backend - dockerfile: Dockerfile + image: ghcr.io/anyesh/wardrowbe:backend-latest container_name: wardrobe-backend extra_hosts: - "host.docker.internal:host-gateway" @@ -78,9 +76,7 @@ services: # Next.js Frontend frontend: - build: - context: ./frontend - dockerfile: Dockerfile + image: ghcr.io/anyesh/wardrowbe:frontend-latest container_name: wardrobe-frontend environment: NEXT_PUBLIC_API_URL: http://backend:8000 @@ -95,9 +91,7 @@ services: # Background Worker for AI Tagging worker: - build: - context: ./backend - dockerfile: Dockerfile + image: ghcr.io/anyesh/wardrowbe:backend-latest container_name: wardrobe-worker command: arq app.workers.worker.WorkerSettings extra_hosts: