From 4f58622b2204feb57943de2305b0cb3a207bbbfa Mon Sep 17 00:00:00 2001 From: Jp Date: Fri, 30 Jan 2026 15:38:11 +0800 Subject: [PATCH] ci: add Docker CI workflows and switch to pre-built image - Add GitHub Actions workflow to build and push Docker image to GitHub Container Registry - Add Gitea workflow for building and pushing Docker image to private registry - Update docker-compose.yml to use pre-built image instead of local build --- .gitea/workflows/docker.yml | 41 ++++++++++++++++++++++++++ .github/workflows/docker.yml | 56 ++++++++++++++++++++++++++++++++++++ docker-compose.yml | 3 +- 3 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 .gitea/workflows/docker.yml create mode 100644 .github/workflows/docker.yml diff --git a/.gitea/workflows/docker.yml b/.gitea/workflows/docker.yml new file mode 100644 index 0000000..cba9845 --- /dev/null +++ b/.gitea/workflows/docker.yml @@ -0,0 +1,41 @@ +name: Build and Push Docker Image (Gitea) +on: + push: + branches: + - main + tags: + - 'v*.*.*' + workflow_dispatch: +permissions: + contents: read + packages: write +env: + REGISTRY: 192.168.100.105:3002 + IMAGE_NAME: calorie-tracker + IMAGE_ID: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 + - uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.CR_USERNAME }} + password: ${{ secrets.CR_PASSWORD }} + - id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.IMAGE_ID }} + tags: | + type=raw,value=latest,enable={{is_default_branch}} + type=ref,event=tag + type=sha + - uses: docker/build-push-action@v5 + with: + context: ./calorie_tracker_app + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..1b1d0e5 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,56 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + tags: + - 'v*.*.*' + workflow_dispatch: + +permissions: + contents: read + packages: write + +env: + REGISTRY: ghcr.io + IMAGE_NAME: calorie-tracker + IMAGE_ID: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }} + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.IMAGE_ID }} + tags: | + type=raw,value=latest,enable={{is_default_branch}} + type=ref,event=tag + type=sha + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: ./calorie_tracker_app + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/docker-compose.yml b/docker-compose.yml index 1e361c9..a0d90c0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,8 +2,7 @@ version: '3.8' services: calorie-tracker: - build: - context: ./calorie_tracker_app + image: 192.168.100.105:3002/kingjaypee12/calorie-tracker:latest container_name: calorie-tracker restart: unless-stopped ports: