-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: Refactor CI to use GitHub actions and generic bash scripts #7
- Loading branch information
Showing
6 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: ci | ||
on: [ push, workflow_dispatch ] | ||
|
||
jobs: | ||
build: | ||
name: Build | ||
if: ${{ !contains(github.event.head_commit.message, 'skip build') }} | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v4 | ||
with: | ||
submodules: true | ||
- name: Init runner | ||
run: bash ./scripts/init_runner.sh ${{ github.job }} | ||
- name: Setup workspace | ||
env: | ||
GITHUB_DEVELOPMENT_TOKEN: ${{ secrets.GH_DEVELOPMENT_TOKEN }} | ||
run: bash ./scripts/setup_workspace.sh | ||
- name: Build theme | ||
env: | ||
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }} | ||
run: bash ./scripts/build.sh -p -r ${{ github.job }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "scripts/kash"] | ||
path = scripts/kash | ||
url = https://github.com/kalisio/kash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
# set -x | ||
|
||
THIS_FILE=$(readlink -f "${BASH_SOURCE[0]}") | ||
THIS_DIR=$(dirname "$THIS_FILE") | ||
ROOT_DIR=$(dirname "$THIS_DIR") | ||
|
||
. "$THIS_DIR/kash/kash.sh" | ||
|
||
## Parse options | ||
## | ||
|
||
PUBLISH=false | ||
CI_STEP_NAME="Build" | ||
while getopts "pr:" option; do | ||
case $option in | ||
p) # publish app | ||
PUBLISH=true | ||
;; | ||
r) # report outcome to slack | ||
CI_STEP_NAME=$OPTARG | ||
trap 'slack_ci_report "$ROOT_DIR" "$CI_STEP_NAME" "$?" "$SLACK_WEBHOOK_SERVICES"' EXIT | ||
;; | ||
*) | ||
;; | ||
esac | ||
done | ||
|
||
## Init workspace | ||
## | ||
|
||
WORKSPACE_DIR="$(dirname "$ROOT_DIR")" | ||
init_lib_infos "$ROOT_DIR" | ||
|
||
LIB=$(get_lib_name) | ||
VERSION=$(get_lib_version) | ||
GIT_TAG=$(get_lib_tag) | ||
|
||
echo "About to build ${LIB} v${VERSION}..." | ||
|
||
load_env_files "$WORKSPACE_DIR/development/common/kalisio_dockerhub.enc.env" "$WORKSPACE_DIR/development/common/SLACK_WEBHOOK_SERVICES.enc.env" | ||
load_value_files "$WORKSPACE_DIR/development/common/KALISIO_DOCKERHUB_PASSWORD.enc.value" | ||
|
||
## Build container | ||
## | ||
|
||
IMAGE_NAME="kalisio/keycloak-themes" | ||
if [[ -z "$GIT_TAG" ]]; then | ||
IMAGE_TAG=latest | ||
else | ||
IMAGE_TAG=$VERSION | ||
fi | ||
|
||
begin_group "Building container ..." | ||
|
||
docker login --username "$KALISIO_DOCKERHUB_USERNAME" --password-stdin < "$KALISIO_DOCKERHUB_PASSWORD" | ||
# DOCKER_BUILDKIT is here to be able to use Dockerfile specific dockerginore (app.Dockerfile.dockerignore) | ||
DOCKER_BUILDKIT=1 docker build \ | ||
-f Dockerfile \ | ||
-t "$IMAGE_NAME:$IMAGE_TAG" \ | ||
"$WORKSPACE_DIR" | ||
|
||
if [ "$PUBLISH" = true ]; then | ||
docker push "$IMAGE_NAME:$IMAGE_TAG" | ||
fi | ||
|
||
docker logout | ||
|
||
end_group "Building container ..." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
# set -x | ||
|
||
JOB_ID=$1 | ||
|
||
THIS_FILE=$(readlink -f "${BASH_SOURCE[0]}") | ||
THIS_DIR=$(dirname "$THIS_FILE") | ||
|
||
. "$THIS_DIR/kash/kash.sh" | ||
|
||
### Github Actions | ||
|
||
init_github_build() { | ||
install_reqs age sops | ||
} | ||
|
||
begin_group "Init $CI_ID for $JOB_ID" | ||
|
||
init_"${CI_ID}_${JOB_ID}" | ||
|
||
end_group "Init $CI_ID for $JOB_ID" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
# set -x | ||
|
||
THIS_FILE=$(readlink -f "${BASH_SOURCE[0]}") | ||
THIS_DIR=$(dirname "$THIS_FILE") | ||
ROOT_DIR=$(dirname "$THIS_DIR") | ||
|
||
. "$THIS_DIR/kash/kash.sh" | ||
|
||
WORKSPACE_BRANCH= | ||
WORKSPACE_TAG= | ||
|
||
begin_group "Setting up workspace ..." | ||
|
||
if [ "$CI" = true ]; then | ||
WORKSPACE_DIR="$(dirname "$ROOT_DIR")" | ||
DEVELOPMENT_REPO_URL="https://$GITHUB_DEVELOPMENT_PAT@github.com/kalisio/development.git" | ||
else | ||
while getopts "b:t" option; do | ||
case $option in | ||
b) # defines branch | ||
WORKSPACE_BRANCH=$OPTARG;; | ||
t) # defines tag | ||
WORKSPACE_TAG=$OPTARG;; | ||
*) | ||
;; | ||
esac | ||
done | ||
|
||
shift $((OPTIND-1)) | ||
WORKSPACE_DIR="$1" | ||
DEVELOPMENT_REPO_URL="$GITHUB_URL/kalisio/development.git" | ||
|
||
# Clone project in the workspace | ||
git_shallow_clone "$GITHUB_URL/kalisio/keycloak-themes.git" "$WORKSPACE_DIR/keycloak-themes" "${WORKSPACE_TAG:-${WORKSPACE_BRANCH:-}}" | ||
fi | ||
|
||
setup_workspace "$WORKSPACE_DIR" "$DEVELOPMENT_REPO_URL" | ||
|
||
end_group "Setting up workspace ..." |