Skip to content

Commit

Permalink
Merge pull request #179 from jembi/dev_ci_update
Browse files Browse the repository at this point in the history
Updating CI workflow (Deploying docker images to docker hub)
  • Loading branch information
walisc authored Feb 22, 2024
2 parents 8113f6a + fa78a2f commit 02090bf
Show file tree
Hide file tree
Showing 35 changed files with 652 additions and 84 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/actions/build-check/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Action > Build

runs:
using: 'composite'
steps:
- uses: ./.github/workflows/actions/cached-dependencies
- name: Build javascript app (ui)
run: |
source "$HOME/.nvm/nvm.sh"
cd $JEMPI_APP_PATH/JeMPI_UI
yarn install --frozen-lockfile
yarn build
shell: bash
- name: Build Scala Apps
run: |
set -eo pipefail
source "$HOME/.sdkman/bin/sdkman-init.sh"
cd $JEMPI_APP_PATH/JeMPI_EM_Scala
sbt clean assembly
shell: bash
- name: Build Java App
run: |
set -eo pipefail
source "$HOME/.sdkman/bin/sdkman-init.sh"
cd $JEMPI_APP_PATH
mvn clean package
shell: bash
25 changes: 25 additions & 0 deletions .github/workflows/actions/build-deploy-images/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Build and Deploy Images
inputs:
docker-push-tag:
required: false
image-build-tag:
required: true
docker-host:
required: true
docker-username:
required: true
docker-password:
required: true
runs:
using: 'composite'
steps:
- uses: ./.github/workflows/actions/docker-images-build
with:
image-build-tag: ${{ inputs.image-build-tag }}
- uses: ./.github/workflows/actions/docker-images-deploy
with:
image-build-tag: ${{ inputs.image-build-tag }}
docker-push-tag: ${{ inputs.docker-push-tag }}
docker-username: ${{ inputs.docker-username }}
docker-password: ${{ inputs.docker-password }}
docker-host: ${{ inputs.docker-host }}
15 changes: 15 additions & 0 deletions .github/workflows/actions/cached-dependencies/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Action > CacheDependencies
runs:
using: 'composite'
steps:
- name: Cache SDKMan Install
uses: actions/cache@v4
with:
path: |
~/.sdkman
~/.nvm
~/.npm
~/.cache/yarn
$GITHUB_WORKSPACE/JeMPI_Apps/JeMPI_UI/node_modules
# Using the prepare file as it contains all the version of the dependencies
key: build-dependencies-${{ hashFiles('**/.github/workflows/actions/prepare/action.yml', '**/yarn.lock') }}
22 changes: 22 additions & 0 deletions .github/workflows/actions/docker-images-build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Action > Docker Images Build
inputs:
image-build-tag:
required: true
runs:
using: 'composite'
steps:
- uses: ./.github/workflows/actions/cached-dependencies
- uses: ./.github/workflows/actions/load-conf-env
- name: Build Docker Images
run: |
set -eo pipefail
source "$HOME/.nvm/nvm.sh"
source "$HOME/.sdkman/bin/sdkman-init.sh"
source $GITHUB_WORKSPACE/devops/linux/docker/conf.env
source $GITHUB_WORKSPACE/devops/linux/docker/conf/images/conf-app-images.sh
pushd $GITHUB_WORKSPACE/JeMPI_Apps
source ./build-all-ci.sh "${{ inputs.image-build-tag }}"
popd
docker image ls
shell: bash

24 changes: 24 additions & 0 deletions .github/workflows/actions/docker-images-deploy/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Deploy Docker Images
inputs:
image-build-tag:
required: true
docker-push-tag:
required: false
docker-host:
required: true
docker-username:
required: true
docker-password:
required: true
runs:
using: 'composite'
steps:
- run: |
set -eo pipefail
source $GITHUB_WORKFLOW_FOLDER/actions/docker-images-deploy/deployDockerImages.sh \
"${{ inputs.image-build-tag }}" \
"${{ inputs.docker-push-tag }}" \
"${{ inputs.docker-host }}" \
"${{ inputs.docker-username }}" \
"${{ inputs.docker-password }}"
shell: bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

original_tag=$1
push_tag=$2
registry_url=$3
username=$4
password=$5

if [ -z "$registry_url" ] || [ -z "$username" ] || [ -z "$password" ]; then
echo "Docker host details not set. Skipping deploying"
exit 0
fi


if [ -z "$push_tag" ]; then
push_tag=$original_tag
fi

if ! docker login "$registry_url" -u "$username" -p "$password"; then
echo "Failed to authenticate with Docker registry. Cannot push."
exit 1
fi


IMAGE_LIST=$(docker image ls --filter "reference=*:$original_tag" --format "{{.Repository}}:{{.Tag}}")

for IMAGE in $IMAGE_LIST; do
IFS=':' read -a image_details <<< "$IMAGE"
push_tag_url="$registry_url/$username/${image_details[0]}:$push_tag"

echo "Pushing image: $IMAGE to '$push_tag_url'"

docker tag "$IMAGE" $push_tag_url
docker push $push_tag_url
done
21 changes: 21 additions & 0 deletions .github/workflows/actions/docker-images-save/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Action > Docker Images Build
inputs:
image-build-tag:
required: true
runs:
using: 'composite'
steps:
- uses: ./.github/workflows/actions/cached-dependencies
- uses: ./.github/workflows/actions/load-conf-env
- name: Build Docker Save
run: |
set -eo pipefail
source $GITHUB_WORKFLOW_FOLDER/actions/docker-images-save/saveImages.sh "${{ inputs.image-build-tag }}" "./.github/workflows/actions/docker-images-save/docker-images"
shell: bash
- uses: actions/upload-artifact@v4
with:
name: docker-images-${{ inputs.image-build-tag }}
path: |
./.github/workflows/actions/docker-images-save/docker-images/
retention-days: 2

15 changes: 15 additions & 0 deletions .github/workflows/actions/docker-images-save/saveImages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

images_path="$2"

if [ ! -d "$images_path" ]; then
mkdir -p "$images_path"
fi

IMAGE_LIST=$(docker image ls --filter "reference=*:$1" --format "{{.Repository}}:{{.Tag}}")

for IMAGE in $IMAGE_LIST; do
IFS=':' read -a image_details <<< "$IMAGE"
echo "Saving image: $IMAGE to '$images_path/${image_details[0]}.${image_details[1]}.tar'"
docker save -o "$images_path/${image_details[0]}.${image_details[1]}.tar" "$IMAGE"
done
24 changes: 24 additions & 0 deletions .github/workflows/actions/install-node/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Install Node
inputs:
node-version:
required: true
runs:
using: 'composite'
steps:
- name: Install Nvm
shell: bash
run: |
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
source "$HOME/.nvm/nvm.sh"
nvm --version
- name: Install node ${{ inputs.node-version }}
run: |
source "$HOME/.nvm/nvm.sh"
nvm install ${{ inputs.node-version }}
shell: bash
- name: Install UI packages
run: |
source "$HOME/.nvm/nvm.sh"
cd $JEMPI_APP_PATH/JeMPI_UI
yarn install --frozen-lockfile
shell: bash
10 changes: 10 additions & 0 deletions .github/workflows/actions/install-sdkman/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Install SDKMan
runs:
using: 'composite'
steps:
- name: Install SDKMan
shell: bash
run: |
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk version
20 changes: 20 additions & 0 deletions .github/workflows/actions/lint/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Action > Lint

runs:
using: 'composite'
steps:
- uses: ./.github/workflows/actions/cached-dependencies
- name: Running javascript linter
run: |
source "$HOME/.nvm/nvm.sh"
cd $JEMPI_APP_PATH/JeMPI_UI
yarn install --frozen-lockfile
yarn lint && yarn format
shell: bash
- name: Running java linter
run: |
set -eo pipefail
source "$HOME/.sdkman/bin/sdkman-init.sh"
source $GITHUB_WORKFLOW_FOLDER/actions/lint/mvn_linter.sh $JEMPI_APP_PATH
shell: bash

11 changes: 11 additions & 0 deletions .github/workflows/actions/lint/mvn_linter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

cd "$1"

for dir in */; do
dir="${dir%/}"
if [ -f "$dir/pom.xml" ]; then
echo "Running Checkstyle for $dir ..."
mvn -f "$dir/pom.xml" checkstyle:check -Dcheckstyle.suppressions.location="$dir/checkstyle/suppression.xml"
fi
done
12 changes: 12 additions & 0 deletions .github/workflows/actions/load-conf-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Action > Load Conf Env

runs:
using: 'composite'
steps:
- name: Load Conf Env
run: |
pushd $GITHUB_WORKSPACE/devops/linux/docker/conf/env
./create-env-linux-high-1.sh
popd
source $GITHUB_WORKSPACE/devops/linux/docker/conf.env
shell: bash
33 changes: 33 additions & 0 deletions .github/workflows/actions/prepare/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Prepare

runs:
using: 'composite'
steps:
- uses: ./.github/workflows/actions/cached-dependencies
id: cache-dependencies
- if: ${{ steps.cache-dependencies.outputs.cache-hit != 'true' }}
name: Set up Node
uses: ./.github/workflows/actions/install-node
with:
node-version: 20
- if: ${{ steps.cache-dependencies.outputs.cache-hit != 'true' }}
name: Set up SDKMan
uses: ./.github/workflows/actions/install-sdkman
- if: ${{ steps.cache-dependencies.outputs.cache-hit != 'true' }}
name: Set up Java
uses: ./.github/workflows/actions/sdkman-installer
with:
candidate: java
version: '21.0.1-tem'
- if: ${{ steps.cache-dependencies.outputs.cache-hit != 'true' }}
name: Set up Maven
uses: ./.github/workflows/actions/sdkman-installer
with:
candidate: maven
version: '3.9.5'
- if: ${{ steps.cache-dependencies.outputs.cache-hit != 'true' }}
name: Set Scala Build Tools
uses: ./.github/workflows/actions/sdkman-installer
with:
candidate: sbt
version: '1.9.8'
15 changes: 15 additions & 0 deletions .github/workflows/actions/sdkman-installer/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: SDKMan Installer
inputs:
candidate:
required: true
version:
required: true
runs:
using: 'composite'
steps:
- name: Installing ${{ inputs.candidate }} (version ${{ inputs.version }})
shell: bash
run: |
echo "$HOME/.sdkman/bin/sdkman-init.sh"
source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk install ${{ inputs.candidate }} ${{ inputs.version }}
7 changes: 7 additions & 0 deletions .github/workflows/actions/smoke-test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: Action > Smoke Test

runs:
using: 'composite'
steps:
- name: Checkout Code
uses: actions/checkout@v4
20 changes: 20 additions & 0 deletions .github/workflows/actions/test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Action > Test

runs:
using: 'composite'
steps:
- uses: ./.github/workflows/actions/cached-dependencies
- name: Testing Java Apps
run: |
set -eo pipefail
source "$HOME/.sdkman/bin/sdkman-init.sh"
cd $JEMPI_APP_PATH
mvn clean test
shell: bash
- name: Testing javascript app (ui)
run: |
source "$HOME/.nvm/nvm.sh"
cd $JEMPI_APP_PATH/JeMPI_UI
yarn install --frozen-lockfile
yarn run test -- --watchAll=false
shell: bash
21 changes: 0 additions & 21 deletions .github/workflows/build.yml

This file was deleted.

Loading

0 comments on commit 02090bf

Please sign in to comment.