Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to use git SHA for release label on Docker image #706

Merged
merged 1 commit into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 37 additions & 30 deletions .github/workflows/build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,48 @@ jobs:
# Ensure that the repo variables and secrets are set before running any other steps
- name: Check User Set Variables
run: |
if [[ -z "$DOCKER_USER" ]]; then \
echo "::error::Secret DOCKER_USER was not set"; \
exit 1; \
if [[ -z "$DOCKER_USER" ]]; then
echo "::error::Secret DOCKER_USER was not set"
exit 1
fi
if [[ -z "$DOCKER_TOKEN" ]]; then \
echo "::error::Secret DOCKER_TOKEN was not set"; \
exit 1; \
if [[ -z "$DOCKER_TOKEN" ]]; then
echo "::error::Secret DOCKER_TOKEN was not set"
exit 1
fi
if [[ -z "$IMAGE_REPO" ]]; then \
echo "::error::Variable DOCKERHUB_REPO was not set"; \
exit 1; \
if [[ -z "$IMAGE_REPO" ]]; then
echo "::error::Variable DOCKERHUB_REPO was not set"
exit 1
fi
if [[ -z "$RUN_NUMBER_OFFSET" ]]; then \
echo "::error::Variable RUN_NUMBER_OFFSET was not set"; \
exit 1; \
if [[ -z "$RUN_NUMBER_OFFSET" ]]; then
echo "::error::Variable RUN_NUMBER_OFFSET was not set"
exit 1
fi
env:
DOCKER_USER: ${{ secrets.DOCKER_USER }}
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}

# Checkout our Github repo
- name: Checkout Github Repo
uses: actions/checkout@v3

# Offset our version build number to prevent collisions
- name: Offset Build Number
id: offset
- name: Configure Env Vars
run: |
echo "BUILD_NUMBER=$(($RUN_NUMBER + $RUN_NUMBER_OFFSET))" >> $GITHUB_ENV
BUILD_NUMBER=$(($RUN_NUMBER + $RUN_NUMBER_OFFSET))
echo "IMAGE_VERSION=$(head -n 1 src/main/resources/version.txt)-$BUILD_NUMBER" >> $GITHUB_ENV
echo "GIT_SHORT_SHA=$(git rev-parse --short "$GITHUB_SHA")" >> $GITHUB_ENV

- name: Validate Env Vars
run: |
echo "Using SHORT SHA: $GIT_SHORT_SHA"
if [[ -z "$GIT_SHORT_SHA" ]]; then
echo "::error::unable to get short sha from $GITHUB_SHA"
exit 1
fi
if [[ -z "$IMAGE_VERSION" ]]; then
echo "::error::unable to get IMAGE_VERSION"
exit 1
fi

# Upgrade Docker engine version, needed for building images.
- name: Install Latest Docker Version
Expand All @@ -64,6 +81,11 @@ jobs:
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Setup Scala
# Comes from open source action: https://github.com/coursier/setup-action
- name: Setup Scala
uses: coursier/setup-action@v1

# Authenticate Dockerhub to allow pushing to our image repo
- name: Login to Dockerhub
uses: docker/login-action@v2
Expand All @@ -78,21 +100,6 @@ jobs:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

# Checkout our Github repo
- name: Checkout Github Repo
uses: actions/checkout@v3

# Setup Scala
# Comes from open source action: https://github.com/coursier/setup-action
- name: Setup Scala
uses: coursier/setup-action@v1

# Configure version variables
- name: Config Version Variables
id: config-version
run: |
echo "IMAGE_VERSION=$(head -n 1 src/main/resources/version.txt)-$BUILD_NUMBER" >> $GITHUB_ENV

# Compile
- name: Compile
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ lazy val root = (project in file("."))
description := "'Containerized exchange-api'",
name := "amd64_exchange-api",
organization := "org.openhorizon",
release := versionFunc(),
release := sys.env.getOrElse("GIT_SHORT_SHA", versionFunc()),
resolvers += Classpaths.typesafeReleases,
scalaVersion := "2.13.10",
summary := "'Open Horizon exchange-api image'",
Expand Down