[IMP] Refactor gateway DNS and align healthcheck #53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| permissions: | |
| contents: read | |
| packages: write | |
| pull-requests: write | |
| name: Build, Test & Deploy | |
| on: | |
| pull_request: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| inputs: | |
| pytest_addopts: | |
| description: | |
| Extra options for pytest; use -vv for full details; see | |
| https://docs.pytest.org/en/latest/example/simple.html#how-to-change-command-line-options-defaults | |
| required: false | |
| env: | |
| LANG: "en_US.utf-8" | |
| LC_ALL: "en_US.utf-8" | |
| PIP_CACHE_DIR: ${{ github.workspace }}/.cache.~/pip | |
| PIPX_HOME: ${{ github.workspace }}/.cache.~/pipx | |
| POETRY_CACHE_DIR: ${{ github.workspace }}/.cache.~/pypoetry | |
| POETRY_VIRTUALENVS_IN_PROJECT: "true" | |
| PYTEST_ADDOPTS: ${{ github.event.inputs.pytest_addopts }} | |
| PYTHONIOENCODING: "UTF-8" | |
| jobs: | |
| build-push: | |
| runs-on: ubuntu-22.04 | |
| services: | |
| registry: | |
| image: registry:2 | |
| ports: | |
| - 5000:5000 | |
| env: | |
| DOCKER_IMAGE_NAME: ${{ github.repository }} | |
| # Push only on non-PR events (push to main/tags, workflow_dispatch) | |
| PUSH: ${{ toJSON(github.event_name != 'pull_request') }} | |
| # Push PR image only for PRs from the same repository | |
| PUSH_PR_IMAGE: | |
| ${{ toJSON(github.event_name == 'pull_request' && | |
| github.event.pull_request.head.repo.full_name == github.repository) }} | |
| steps: | |
| # Set up Docker Environment | |
| - uses: actions/checkout@v4 | |
| - uses: actions/cache@v4 | |
| with: | |
| path: | | |
| /tmp/.buildx-cache | |
| key: buildx|${{ secrets.CACHE_DATE }}|${{ runner.os }} | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v1 | |
| - name: Set up Docker Buildx | |
| id: buildx | |
| uses: docker/setup-buildx-action@v1 | |
| with: | |
| driver-opts: network=host | |
| install: true | |
| # Build and push (always) to local (test) registry | |
| - name: Docker meta for local images | |
| id: docker_meta_local | |
| uses: crazy-max/ghaction-docker-meta@v1 | |
| with: | |
| images: localhost:5000/${{ env.DOCKER_IMAGE_NAME }} | |
| tag-edge: true | |
| tag-semver: | | |
| {{version}} | |
| {{major}} | |
| {{major}}.{{minor}} | |
| - name: Build and push to local (test) registry | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| platforms: | | |
| linux/386 | |
| linux/amd64 | |
| linux/arm64 | |
| load: false | |
| push: true | |
| cache-from: type=local,src=/tmp/.buildx-cache | |
| cache-to: type=local,dest=/tmp/.buildx-cache,mode=max | |
| labels: ${{ steps.docker_meta_local.outputs.labels }} | |
| tags: ${{ steps.docker_meta_local.outputs.tags }} | |
| - name: Debug context | |
| run: | | |
| echo "Actor: $GITHUB_ACTOR" | |
| echo "Event: $GITHUB_EVENT_NAME" | |
| echo "Ref: $GITHUB_REF" | |
| echo "PUSH: ${{ env.PUSH }}" | |
| echo "PR: ${{ env.PUSH_PR_IMAGE }}" | |
| - name: Login to GitHub Container Registry | |
| if: ${{ fromJSON(env.PUSH) || fromJSON(env.PUSH_PR_IMAGE) }} | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Docker meta for GHCR | |
| if: ${{ fromJSON(env.PUSH) }} | |
| id: docker_meta_public | |
| uses: crazy-max/ghaction-docker-meta@v1 | |
| with: | |
| images: | | |
| ghcr.io/tecnativa/docker-whitelist-gateway-service | |
| tag-edge: true | |
| tag-semver: | | |
| {{version}} | |
| {{major}} | |
| {{major}}.{{minor}} | |
| - name: Build and push to GHCR | |
| if: ${{ fromJSON(env.PUSH) }} | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| platforms: | | |
| linux/386 | |
| linux/amd64 | |
| linux/arm64 | |
| load: false | |
| push: true | |
| provenance: false | |
| cache-from: type=local,src=/tmp/.buildx-cache | |
| cache-to: type=local,dest=/tmp/.buildx-cache,mode=max | |
| labels: ${{ steps.docker_meta_public.outputs.labels }} | |
| tags: ${{ steps.docker_meta_public.outputs.tags }} | |
| - name: Docker meta for PR image | |
| if: ${{ fromJSON(env.PUSH_PR_IMAGE) }} | |
| id: docker_meta_pr | |
| uses: crazy-max/ghaction-docker-meta@v1 | |
| with: | |
| images: | | |
| ghcr.io/tecnativa/docker-whitelist-gateway-service | |
| tags: | | |
| type=raw,value=pr-${{ github.event.pull_request.number }} | |
| type=raw,value=pr-${{ github.event.pull_request.number }}-${{ github.sha }} | |
| - name: Build and push PR image to GHCR | |
| if: ${{ fromJSON(env.PUSH_PR_IMAGE) }} | |
| uses: docker/build-push-action@v4 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| platforms: | | |
| linux/386 | |
| linux/amd64 | |
| linux/arm64 | |
| load: false | |
| push: true | |
| provenance: false | |
| cache-from: type=local,src=/tmp/.buildx-cache | |
| cache-to: type=local,dest=/tmp/.buildx-cache,mode=max | |
| labels: ${{ steps.docker_meta_pr.outputs.labels }} | |
| tags: ${{ steps.docker_meta_pr.outputs.tags }} | |
| - name: Comment PR with test image | |
| if: ${{ fromJSON(env.PUSH_PR_IMAGE) }} | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const pr = context.payload.pull_request.number; | |
| const owner = context.repo.owner; | |
| const repo = context.repo.repo; | |
| const image = `ghcr.io/tecnativa/docker-whitelist-gateway-service:pr-${pr}`; | |
| const marker = "<!-- pr-test-image-comment -->"; | |
| const body = `${marker} | |
| Test image published: | |
| \`${image}\``; | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner, | |
| repo, | |
| issue_number: pr, | |
| per_page: 100, | |
| }); | |
| const existing = comments.find(comment => | |
| comment.user?.type === "Bot" && | |
| comment.body?.includes(marker) | |
| ); | |
| if (existing) { | |
| await github.rest.issues.updateComment({ | |
| owner, | |
| repo, | |
| comment_id: existing.id, | |
| body, | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| owner, | |
| repo, | |
| issue_number: pr, | |
| body, | |
| }); | |
| } |