Skip to content

Commit

Permalink
Fix app version in container images
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed May 10, 2022
1 parent 1b764f8 commit 954f02e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/gating.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,12 @@ jobs:
image: ${{ env.IMAGE_NAME }}
tags: >-
${{ github.ref == 'refs/heads/master' && 'latest' || '' }}
${{ github.ref_name }}
${{ github.sha }}
containerfiles: Dockerfile
build-args: |
GITHUB_SHA=${{ github.sha }}
GITHUB_REF=${{ github.ref }}
- name: Log in to the image registry
if: github.event_name == 'push' && github.actor != 'dependabot[bot]'
Expand Down
15 changes: 11 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,28 @@ ENV PYTHONFAULTHANDLER=1 \
FROM base as builder

RUN microdnf install -y --nodocs --setopt install_weak_deps=0 \
git-core \
python39 \
python39-pip

ARG GITHUB_REF
ARG GITHUB_SHA

ENV PIP_DEFAULT_TIMEOUT=100 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_NO_CACHE_DIR=1
PIP_NO_CACHE_DIR=1 \
GITHUB_REF=$GITHUB_REF \
GITHUB_SHA=$GITHUB_SHA

WORKDIR /build
COPY . .
# hadolint ignore=SC1091
RUN set -ex \
&& version=$(./get-version.sh) \
&& test -n "$version" \
&& pip3 install --no-cache-dir -r requirements-builder.txt \
&& python3 -m venv /venv \
&& . /venv/bin/activate \
&& pip install --no-cache-dir -r requirements-builder2.txt \
&& version=$(./get-version.sh) \
&& test -n "$version" \
&& poetry version "$version" \
&& poetry install --no-dev --no-root \
&& poetry build \
Expand All @@ -37,10 +41,13 @@ RUN set -ex \

# --- Final image
FROM base as greenwave
ARG GITHUB_SHA
LABEL \
name="Greenwave application" \
vendor="Greenwave developers" \
license="GPLv2+" \
vcs-type="git" \
vcs-ref=$GITHUB_SHA \
build-date=""

WORKDIR /src
Expand Down
11 changes: 11 additions & 0 deletions get-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
set -e

name=greenwave

if [[ -n "$GITHUB_SHA" ]]; then
if [[ $GITHUB_REF =~ ^ref/tags/$name- ]]; then
echo "${GITHUB_REF#refs/tags/$name-}"
else
last_version=$(poetry version --short)
echo "$last_version+git.${GITHUB_SHA:0:7}"
fi
exit
fi

if [ "$(git tag | wc -l)" -eq 0 ] ; then
# never been tagged since the project is just starting out
lastversion="0.0"
Expand Down

0 comments on commit 954f02e

Please sign in to comment.