Skip to content

Commit

Permalink
Expose version information (#1116)
Browse files Browse the repository at this point in the history
* chore: use docker metadata to add tags and labels to containers

* chore: add more triggers for docker builds

* chore: reduce how many jobs get created

* chore: add caching to builds

* feat: inject version info to container

* feat: display version in API docs

* feat: more details about running version

* fix: add merge_group as trigger so branch protection rules can get satisfied when working with merge queues
  • Loading branch information
niekcandaele authored Aug 17, 2024
1 parent 7bb72aa commit c236b72
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 31 deletions.
61 changes: 30 additions & 31 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
name: Docker

on: [push]
on:
push:
branches:
- 'main'
- 'development'
tags:
- '*'
merge_group:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -10,7 +18,7 @@ jobs:
docker:
runs-on: ubuntu-24.04
outputs:
docker_tag: ${{ steps.prep.outputs.version }}
docker_tag: ${{ steps.meta.outputs.version }}
strategy:
matrix:
package:
Expand All @@ -36,40 +44,22 @@ jobs:
script: |
const repo = await github.rest.repos.get(context.repo)
return repo.data
- name: Prepare
id: prep
run: |
DOCKER_IMAGE=ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}-${{ matrix.package.name }}
VERSION=noop
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION=nightly
elif [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
VERSION=latest
fi
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
MINOR=${VERSION%.*}
MAJOR=${MINOR%.*}
TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}-${{ matrix.package.name }}

- name: Get Git commit timestamps
run: echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
if: ${{ !startsWith(github.actor, 'dependabot') }}
if: ${{ !startsWith(github.actor, 'renovate') }}
uses: docker/login-action@v2
with:
registry: ghcr.io
Expand All @@ -81,11 +71,20 @@ jobs:
uses: docker/build-push-action@v4
with:
context: .
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}-${{ matrix.package.name }}:latest
cache-to: type=inline
sbom: true
file: ${{ matrix.package.dockerfile }}
push: ${{ !startsWith(github.actor, 'dependabot') }}
tags: ${{ steps.prep.outputs.tags }}
push: ${{ !startsWith(github.actor, 'renovate') }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
PACKAGE=${{ matrix.package.name }}
TAKARO_VERSION=${{ steps.meta.outputs.version }}
TAKARO_COMMIT=${{ github.sha }}
TAKARO_BUILD_DATE=${{ env.TIMESTAMP }}
env:
SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP }}
node-ci:
needs: [docker]
timeout-minutes: 60
Expand Down
5 changes: 5 additions & 0 deletions containers/generic-app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ ARG PACKAGE
ENV PACKAGE=${PACKAGE}
ENV NODE_ENV=production

ARG TAKARO_VERSION=unset
ARG TAKARO_COMMIT=unset
ARG TAKARO_BUILD_DATE=unset
ENV TAKARO_FULL_VERSION=${TAKARO_VERSION}-${TAKARO_COMMIT}-${TAKARO_BUILD_DATE}

WORKDIR /app

COPY --from=builder /app/packages/${PACKAGE}/package*.json /app/packages/${PACKAGE}/
Expand Down
6 changes: 6 additions & 0 deletions containers/generic-web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ WORKDIR /app
COPY containers/generic-web/entrypoint.sh ./entrypoint.sh
RUN chmod +x ./entrypoint.sh

ARG TAKARO_VERSION=unset
ARG TAKARO_COMMIT=unset
ARG TAKARO_BUILD_DATE=unset
ENV TAKARO_FULL_VERSION=${TAKARO_VERSION}-${TAKARO_COMMIT}-${TAKARO_BUILD_DATE}
ENV VITE_TAKARO_VERSION=${TAKARO_FULL_VERSION}

CMD ["./entrypoint.sh"]
5 changes: 5 additions & 0 deletions containers/takaro/dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ WORKDIR /app

RUN npm ci

ARG TAKARO_VERSION=localdev
ARG TAKARO_COMMIT=unset
ARG TAKARO_BUILD_DATE=unset
ENV TAKARO_FULL_VERSION=${TAKARO_VERSION}-${TAKARO_COMMIT}-${TAKARO_BUILD_DATE}

CMD ["npm", "run", "start:dev"]
9 changes: 9 additions & 0 deletions packages/lib-http/src/controllers/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ export class Meta {
storage,
{},
{
info: {
title: `Takaro ${process.env.PACKAGE || 'API'}`,
version: process.env.TAKARO_FULL_VERSION || '0.0.0',
contact: {
name: 'Takaro Team',
email: '[email protected]',
url: 'https://takaro.io',
},
},
components: {
schemas,
securitySchemes: {
Expand Down

0 comments on commit c236b72

Please sign in to comment.