Skip to content

Push Docker image

Push Docker image #1

name: Build, test and push image
on:
push:
workflow_dispatch:
jobs:
build-test-push:
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Expose GitHub Runtime
uses: crazy-max/ghaction-github-runtime@v3
- name: Check out repository code
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- name: Build image
run: |
docker buildx build \
--output=type=docker \
--cache-to type=gha,mode=max \
--cache-from type=gha \
--load \
--progress=plain \
--iidfile=iid \
.
- name: Run tests
run: |
docker run --rm $(<iid) test
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Tag and push image
run: |
docker tag $(<iid) rootmos/silly-k:$GITHUB_SHA
docker push rootmos/silly-k:$GITHUB_SHA
- name: Mark as latest image
if: github.ref_name == 'master'
run: |
docker tag $(<iid) rootmos/silly-k:latest
docker push rootmos/silly-k:latest