Add a docker section #1
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: Docker | ||
# Limit concurrent runs of this workflow within a single PR | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | ||
cancel-in-progress: true | ||
on: | ||
push: | ||
branches: [ "master" ] | ||
tags: [ "*.*.*" ] | ||
jobs: | ||
docker: | ||
strategy: | ||
matrix: | ||
target: [ easy-rider ] | ||
runs-on: ubuntu-latest | ||
steps: | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install Nix | ||
uses: DeterminateSystems/nix-installer-action@v4 | ||
- name: Run the Magic Nix Cache | ||
uses: DeterminateSystems/magic-nix-cache-action@v2 | ||
- name: 🔨 Build image using nix | ||
run: | | ||
IMAGE_NAME=ghcr.io/${{github.repository_owner}}/${{matrix.target}} | ||
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV | ||
nix build .#docker-${{ matrix.target }} && docker load < ./result | ||
# Determine whether we are building a tag and if yes, set a VERSION_NAME | ||
BUILDING_TAG=${{github.ref_type == 'tag'}} | ||
[[ ${BUILDING_TAG} = true ]] && \ | ||
VERSION_NAME=${{github.ref_name}} | ||
# Use 'FROM' instruction to use docker build with --label | ||
echo "FROM ${{matrix.target}}" | docker build \ | ||
--label org.opencontainers.image.source=https://github.com/devnull/easy-rider \ | ||
--label org.opencontainers.image.licenses=Apache-2.0 \ | ||
--label org.opencontainers.image.created=$(date -Is) \ | ||
--label org.opencontainers.image.revision=${{github.sha}} \ | ||
--label org.opencontainers.image.version=${VERSION_NAME:-unstable} \ | ||
--tag ${IMAGE_NAME}:unstable - | ||
docker tag ${IMAGE_NAME}:unstable ${IMAGE_NAME}:latest | ||
docker images | ||
docker inspect ${IMAGE_NAME}:unstable | ||