Skip to content

feat(init): Initial commit #4

feat(init): Initial commit

feat(init): Initial commit #4

Workflow file for this run

name: Docker
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- main
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
docker-build:
name: Build Docker Images
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ vars.GO_VERSION }}
cache-dependency-path: "**/*.sum"
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Shorten hash
id: shorten_hash
run: echo "HASH=$(git rev-parse --short ${{ github.sha }})" >> $GITHUB_OUTPUT
- name: Build app
run: |
docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.HASH }} -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest .
echo "hash=$hash" >> $GITHUB_ENV
- name: Push app
if: ${{ github.event_name != 'pull_request' }}
run: |
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$hash
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest