feat(docker): Set additional labels #245
Workflow file for this run
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 & Publish Parsec Server Docker Image | |
# cspell:words buildx | |
on: | |
workflow_dispatch: | |
pull_request: | |
paths: | |
- server/packaging/server/** | |
- .github/workflows/docker-server.yml | |
# Only run on pushed tag because we don't want this workflow to run everytime we push something to the main branch. | |
push: | |
tags: | |
- v[0-9]+.[0-9]+.[0-9]+* | |
- nightly | |
permissions: | |
contents: write | |
packages: write | |
# We set `concurrency` to prevent having this workflow being run on code that is not up-to-date on a PR (a user make multiple push in a quick manner). | |
# But outside of a PR, we want to have only 1 workflow to be run at the same time on a given git ref | |
concurrency: | |
group: docker-server-${{ github.workflow }}-${{ github.head_ref || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
docker-server: | |
runs-on: ubuntu-22.04 | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin v4.2.2 | |
timeout-minutes: 3 | |
# Set up BuildKit Docker container builder to be able to build | |
# multi-platform images and export cache | |
# https://github.com/docker/setup-buildx-action | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@f7ce87c1d6bead3e36075b2ce75da1f6cc28aaca # v3.9.0 | |
- name: Log in to the Github Container registry | |
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Install python | |
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # pin v5.4.0 | |
id: setup-python | |
with: | |
python-version: 3.12 | |
- name: Get current version | |
id: version | |
run: python misc/releaser.py version --uniq-dev | tee -a $GITHUB_OUTPUT | |
timeout-minutes: 1 | |
- name: Generate build metadata | |
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5.6.1 | |
id: metadata | |
with: | |
images: | |
ghcr.io/scille/parsec-cloud/parsec-server | |
# Manually set some labels: | |
# - The title to be more specific than just the repo name. | |
# - The license label as it's not correctly detect by the action | |
# (internally it use the detected license from github but itself does not support our license) | |
# - The documentation URL | |
# - The version labels to the full version. | |
# | |
# We use the spec defined here: https://github.com/opencontainers/image-spec/blob/main/annotations.md | |
labels: | | |
org.opencontainers.image.title=The Parsec-Cloud server | |
org.opencontainers.image.licenses=BUSL-1.1 | |
org.opencontainers.image.documentation=https://docs.parsec.cloud/en/stable/hosting/introduction.html | |
org.opencontainers.image.version=${{ steps.version.outputs.full }} | |
tags: | | |
type=semver,pattern={{ version }} | |
type=semver,pattern={{ major }}.{{ minor }} | |
type=raw,value=${{ steps.version.outputs.docker }} | |
type=schedule,enable=${{ github.event_name == 'push' && github.ref_type == 'tag' && github.ref == 'refs/tags/nightly' && 'true' || 'false' }},pattern=nightly | |
flavor: | | |
latest=${{ github.event_name == 'push' && github.ref_type == 'tag' }} | |
- name: Build and export to Docker | |
uses: docker/build-push-action@0adf9959216b96bec444f325f1e493d4aa344497 # v6.14.0 | |
id: build | |
with: | |
context: . | |
file: server/packaging/server/server.dockerfile | |
load: true | |
tags: ${{ steps.metadata.outputs.tags }} | |
labels: ${{ steps.metadata.outputs.labels }} | |
push: false | |
timeout-minutes: 20 | |
- name: Start docker test container | |
id: test-container | |
shell: bash | |
run: | | |
( | |
echo -n "id="; | |
docker run --detach --publish 6777:6777 --rm --name=parsec-server ${{ steps.build.outputs.imageid }} -- run --port=6777 --dev --host=0.0.0.0 | |
) | tee $GITHUB_OUTPUT | |
timeout-minutes: 1 | |
- name: Test docker image | |
run: python .github/scripts/test-server.py | |
timeout-minutes: 1 | |
- name: Stop docker test container | |
run: docker container stop ${{ steps.test-container.outputs.id }} | |
timeout-minutes: 1 | |
- name: Image to be published | |
run: echo "${{ steps.metadata.outputs.tags }}" | |
- name: Build and publish | |
uses: docker/build-push-action@0adf9959216b96bec444f325f1e493d4aa344497 # v6.14.0 | |
id: publish | |
with: | |
context: . | |
file: server/packaging/server/server.dockerfile | |
tags: ${{ steps.metadata.outputs.tags }} | |
labels: ${{ steps.metadata.outputs.labels }} | |
push: ${{ (github.event_name == 'push' && github.ref_type == 'tag') || github.event_name == 'workflow_dispatch' }} |