Skip to content

Commit

Permalink
ci: added node and debian version as args to Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbourianes-kalisio committed Jul 19, 2024
1 parent 26687c1 commit 4b3719c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ jobs:
name: Build service
if: ${{ !contains(github.event.head_commit.message, 'skip build') }}
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
node: [ 20 ]
debian: [ 'bookworm' ]
steps:
- name: Checkout repo
uses: actions/checkout@v4
Expand All @@ -65,4 +70,4 @@ jobs:
- name: Build service
env:
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
run: bash ./scripts/build_service.sh -p -r ${{ github.job }}
run: bash ./scripts/build_service.sh -p -r ${{ github.job }} -n ${{ matrix.node }} -d ${{ matrix.debian }}
7 changes: 5 additions & 2 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
ARG DEBIAN_VERSION=bookworm
ARG NODE_VERSION=20

# Build
FROM node:16.17-bullseye-slim AS builder
FROM node:${NODE_VERSION}-${DEBIAN_VERSION}-slim AS builder
ENV HOME /k2
COPY . ${HOME}
WORKDIR ${HOME}
RUN yarn

# Copy to slim image
FROM node:16.17-bullseye-slim
FROM node:${NODE_VERSION}-${DEBIAN_VERSION}-slim
LABEL maintainer "<[email protected]>"

# In case you use an apt proxy somewhere
Expand Down
24 changes: 21 additions & 3 deletions scripts/build_service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@ WORKSPACE_DIR="$(dirname "$ROOT_DIR")"
## Parse options
##

DEFAULT_NODE_VER=20
DEFAULT_DEBIAN_VER=bookworm
NODE_VER=$DEFAULT_NODE_VER
DEBIAN_VER=$DEFAULT_DEBIAN_VER
PUBLISH=false
CI_STEP_NAME="Build service"
while getopts "pr:" option; do
while getopts "d:n:pr:" option; do
case $option in
d) # defines debian version
DEBIAN_VER=$OPTARG
;;
n) # defines node version
NODE_VER=$OPTARG
;;
p) # publish app
PUBLISH=true
;;
Expand Down Expand Up @@ -50,23 +60,31 @@ load_value_files "$WORKSPACE_DIR/development/common/KALISIO_DOCKERHUB_PASSWORD.e
##

IMAGE_NAME="$KALISIO_DOCKERHUB_URL/kalisio/$NAME"
IMAGE_TAG=latest
IMAGE_SHORT_TAG=latest

if [[ -n "$GIT_TAG" ]]; then
IMAGE_TAG=$VERSION
IMAGE_SHORT_TAG=$VERSION
fi

IMAGE_TAG="$IMAGE_SHORT_TAG-node$NODE_VER-$DEBIAN_VER"

begin_group "Building container $IMAGE_NAME:$IMAGE_TAG ..."

docker login --username "$KALISIO_DOCKERHUB_USERNAME" --password-stdin "$KALISIO_DOCKERHUB_URL" < "$KALISIO_DOCKERHUB_PASSWORD"
# DOCKER_BUILDKIT is here to be able to use Dockerfile specific dockerginore (app.Dockerfile.dockerignore)
DOCKER_BUILDKIT=1 docker build \
--build-arg NODE_VERSION="$NODE_VER" \
--build-arg DEBIAN_VERSION="$DEBIAN_VER" \
-f Dockerfile \
-t "$IMAGE_NAME:$IMAGE_TAG" \
"$ROOT_DIR"

if [ "$PUBLISH" = true ]; then
docker push "$IMAGE_NAME:$IMAGE_TAG"
if [ "$NODE_VER" = "$DEFAULT_NODE_VER" ] && [ "$DEBIAN_VER" = "$DEFAULT_DEBIAN_VER" ]; then
docker tag "$IMAGE_NAME:$IMAGE_TAG" "$IMAGE_NAME:$IMAGE_SHORT_TAG"
docker push "$IMAGE_NAME:$IMAGE_SHORT_TAG"
fi
fi

docker logout "$KALISIO_DOCKERHUB_URL"
Expand Down

0 comments on commit 4b3719c

Please sign in to comment.