Move docker image build to github actions #7
This file contains 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
name: Build Docker Image | |
on: | |
push: | |
branches: [main, master] | |
pull_request: | |
branches: [main, master] | |
env: | |
TAG_LOADBALANCER: mrcide/hintr-loadbalancer | |
TAG_LOADBALANCER_GHCR: mrc-ide/hintr-loadbalancer | |
jobs: | |
docker: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- id: extract_branch | |
name: Setup Environment | |
shell: bash | |
run: | | |
if [ "${{github.event_name}}" = "pull_request" ]; | |
then | |
LONG_SHA=${{ github.event.pull_request.head.sha }} | |
echo "CI_BRANCH=${{ github.head_ref }}" >> $GITHUB_OUTPUT | |
else | |
LONG_SHA=${GITHUB_SHA} | |
echo "CI_BRANCH=${{ github.ref_name }}" >> $GITHUB_OUTPUT | |
fi | |
echo "CI_SHA=${LONG_SHA:0:7}" >> $GITHUB_OUTPUT | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Login to GHCR (GitHub Packages) | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build dev loadbalancer container | |
uses: docker/build-push-action@v6 | |
if: github.event_name == 'pull_request' | |
with: | |
load: true | |
tags: | | |
${{env.TAG_LOADBALANCER}}:${{steps.extract_branch.outputs.CI_BRANCH}} | |
ghcr.io/${{env.TAG_LOADBALANCER_GHCR}}:${{steps.extract_branch.outputs.CI_BRANCH}} | |
- name: Build prod loadbalancer container | |
uses: docker/build-push-action@v6 | |
if: github.event_name != 'pull_request' | |
with: | |
load: true | |
tags: | | |
${{env.TAG_LOADBALANCER}}:latest | |
${{env.TAG_LOADBALANCER}}:${{steps.extract_branch.outputs.CI_BRANCH}} | |
ghcr.io/${{env.TAG_LOADBALANCER_GHCR}}:latest | |
ghcr.io/${{env.TAG_LOADBALANCER_GHCR}}:${{steps.extract_branch.outputs.CI_BRANCH}} | |
- name: Setup tmate session | |
uses: mxschmitt/action-tmate@v3 | |
- name: Test loadbalancer container | |
run: ./test | |
env: | |
TAG_BRANCH: ${{env.TAG_LOADBALANCER}}:${{steps.extract_branch.outputs.CI_BRANCH}} | |
- name: Push dev loadbalancer container | |
uses: docker/build-push-action@v6 | |
if: github.event_name == 'pull_request' | |
with: | |
push: true | |
tags: | | |
${{env.TAG_LOADBALANCER}}:${{steps.extract_branch.outputs.CI_BRANCH}} | |
ghcr.io/${{env.TAG_LOADBALANCER_GHCR}}:${{steps.extract_branch.outputs.CI_BRANCH}} | |
- name: Push prod loadbalancer container | |
uses: docker/build-push-action@v6 | |
if: github.event_name != 'pull_request' | |
with: | |
push: true | |
tags: | | |
${{env.TAG_LOADBALANCER}}:latest | |
${{env.TAG_LOADBALANCER}}:${{steps.extract_branch.outputs.CI_BRANCH}} | |
ghcr.io/${{env.TAG_LOADBALANCER_GHCR}}:latest | |
ghcr.io/${{env.TAG_LOADBALANCER_GHCR}}:${{steps.extract_branch.outputs.CI_BRANCH}} |