Skip to content

HTTP fails and stops the container #472

HTTP fails and stops the container

HTTP fails and stops the container #472

name: Pull Request publish
on:
issue_comment:
types: [created]
env:
# TODO: Change variable to your image's name.
DOCKERHUB_IMAGE_NAME: thomx/fr24feed-piaware
GHCR_IMAGE_NAME: thom-x/docker-fr24feed-piaware-dump1090
jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
is_deploy_comment:
outputs:
is_deploy: ${{ steps.check.outputs.triggered }}
# Ensure test job passes before pushing image.
runs-on: ubuntu-latest
if: github.event.issue.pull_request
steps:
- name: If deploy comment
env:
COMMENT: ${{ github.event.comment.body }}
id: check
run: |
if [[ "${COMMENT}" == "@deploy" ]]; then
echo "Proceeding..."
echo "triggered=true" >> $GITHUB_OUTPUT
else
echo "triggered=false" >> $GITHUB_OUTPUT
curl -f -s -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/cancel
sleep 60s
exit 42
fi
test:
needs: is_deploy_comment
if: needs.is_deploy_comment.outputs.is_deploy == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: 'refs/pull/${{ github.event.issue.number }}/merge'
- name: Get commit
id: get_commit
run: |
echo "sha_short=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: all-buildx-${{ steps.get_commit.outputs.sha_short }}
restore-keys: |
all-buildx-
- name: Build
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
push: false
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
# Push image to GitHub Packages and Docker Hub.
push:
# Ensure test job passes before pushing image.
needs: test
environment: docker
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: 'refs/pull/${{ github.event.issue.number }}/merge'
- name: Get commit
id: get_commit
run: |
echo "sha_short=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: all-buildx-${{ steps.get_commit.outputs.sha_short }}
restore-keys: |
all-buildx-
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get tags list
id: tags
run: |
TAGS=$DOCKERHUB_IMAGE_NAME:PR-${{ github.event.issue.number }},ghcr.io/$GHCR_IMAGE_NAME:PR-${{ github.event.issue.number }}
echo TAGS=$TAGS
echo "tags=$TAGS" >> $GITHUB_OUTPUT
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
push: true
tags: ${{ steps.tags.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache