From 2f763ddc0cd48be7edede1ef6f17370c8190fa49 Mon Sep 17 00:00:00 2001 From: hoelee Date: Mon, 10 Aug 2026 06:16:32 +0800 Subject: [PATCH] Add Docker Hub CI/CD workflow --- .github/workflows/docker.yml | 62 ++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..484c1bd --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,62 @@ +name: Build & Push to Docker Hub + +on: + push: + branches: [main] + tags: ["v*"] + pull_request: + branches: [main] + +env: + REGISTRY: docker.io + IMAGE_NAME: ${{ vars.DOCKERHUB_USERNAME }}/email-sync-oauth2 + +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 Docker Hub + if: github.event_name != "pull_request" + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + push: ${{ github.event_name != "pull_request" }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Run healthcheck test + if: github.event_name == 'pull_request' + run: | + docker compose up -d + sleep 30 + docker inspect --format='{{.State.Health.Status}}' email-sync-oauth2 + docker compose down