58 lines
2.1 KiB
YAML
58 lines
2.1 KiB
YAML
# Builds the image and pushes it. It does not deploy.
|
|
#
|
|
# What picks it up is a timer on the server (see `deploy/`), so nothing here
|
|
# holds a credential for the machine it runs on and a bad build cannot take the
|
|
# service down by itself. The trade is that a deploy happens a few minutes
|
|
# after the push rather than at the moment of it.
|
|
|
|
name: Image
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- 'v*'
|
|
|
|
jobs:
|
|
image:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Compute short sha
|
|
id: short
|
|
run: echo "sha=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
|
|
|
|
- uses: docker/setup-buildx-action@v3
|
|
|
|
- uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ vars.REGISTRY }}
|
|
username: ${{ vars.USERNAME }}
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
|
|
# Tagged with the commit as well as `latest`, so that "what is actually
|
|
# running" has an answer, and so a rollback is a tag rather than a revert
|
|
# and a rebuild. On a `v*` tag build the tag name is added too, so an
|
|
# exact version can be pinned; on branch pushes that expression is empty
|
|
# and the line is dropped. The version build-arg/label follow the same
|
|
# rule and feed /api/version through the Dockerfile's ARGs.
|
|
- uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: ./Dockerfile
|
|
push: true
|
|
build-args: |
|
|
NEWS_BUILD_VERSION=${{ github.ref_type == 'tag' && github.ref_name || 'dev' }}
|
|
NEWS_BUILD_SHA=${{ github.sha }}
|
|
labels: |
|
|
org.opencontainers.image.version=${{ github.ref_type == 'tag' && github.ref_name || 'dev' }}
|
|
org.opencontainers.image.revision=${{ github.sha }}
|
|
tags: |
|
|
${{ vars.REGISTRY }}/connor/news:latest
|
|
${{ vars.REGISTRY }}/connor/news:${{ steps.short.outputs.sha }}
|
|
${{ vars.REGISTRY }}/connor/news:${{ github.ref_type == 'tag' && github.ref_name || '' }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|