Skip to content

Commit

Permalink
wip: Refactor CI to use GitHub actions and generic bash scripts #27
Browse files Browse the repository at this point in the history
  • Loading branch information
cnouguier committed Apr 18, 2024
1 parent e288021 commit a454c31
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 70 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
variant: [hydro-stations, hydro-observations, hydro-predictions, piezo-stations, piezo-observations]
variant: [ hydro-stations, hydro-observations, hydro-predictions, piezo-stations, piezo-observations ]
steps:
- name: Checkout repo
uses: actions/checkout@v4
Expand All @@ -23,5 +23,5 @@ jobs:
- name: Build job
env:
SOPS_AGE_KEY: ${{ secrets.SOPS_AGE_KEY }}
run: bash ./scripts/build.sh -p -r ${{ github.job }} ${{ matrix.variant }}
run: bash ./scripts/build.sh -p -r ${{ github.job }} ${{ matrix.variant }} -v ${{ matrix.variant }}

67 changes: 19 additions & 48 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,69 +13,40 @@ WORKSPACE_DIR="$(dirname "$ROOT_DIR")"
##

PUBLISH=false
while getopts "prv" option; do
JOB_VARIANT=
WORKFLOW_JOB_ID=
while getopts "pr:v:" option; do
case $option in
p) # publish
PUBLISH=true
;;
r) # report outcome to slack
WORKFLOW_JOB_ID=$OPTARG
load_env_files "$WORKSPACE_DIR/development/common/SLACK_WEBHOOK_JOBS.enc.env"
trap 'slack_ci_report "$ROOT_DIR" "$JOB_ID $JOB_VARIANT" "$?" "$SLACK_WEBHOOK_JOBS"' EXIT
trap 'slack_ci_report "$ROOT_DIR" "$WORKFLOW_JOB_ID $JOB_VARIANT" "$?" "$SLACK_WEBHOOK_JOBS"' EXIT
;;
v) # job variant
JOB_VARIANT=$OPTARG
;;
*)
;;
esac
done

shift $((OPTIND-1))
JOB_ID="$1"

## Init workspace
## Init worksapce
##

init_job_infos "$ROOT_DIR"

JOB=$(get_job_name)
VERSION=$(get_job_version)
KRAWLER_VERSION=$(get_job_krawler_version)
GIT_TAG=$(get_job_tag)

if [[ -z "$GIT_TAG" ]]; then
echo "About to build ${JOB} development version based on krawler development version..."
else
echo "About to build ${JOB} v${VERSION} based on krawler ${KRAWLER_VERSION}..."
fi

load_env_files "$WORKSPACE_DIR/development/common/kalisio_dockerhub.enc.env" "$WORKSPACE_DIR/development/common/SLACK_WEBHOOK_JOBS.enc.env"
load_env_files "$WORKSPACE_DIR/development/common/kalisio_dockerhub.enc.env"
load_value_files "$WORKSPACE_DIR/development/common/KALISIO_DOCKERHUB_PASSWORD.enc.value"

## Build container
## Build job
##

JOB_VARIANT="$2"
IMAGE_NAME="kalisio/$JOB"
if [[ -z "$GIT_TAG" ]]; then
IMAGE_TAG="$JOB_VARIANT-latest"
KRAWLER_TAG=latest
else
IMAGE_TAG="$JOB_VARIANT-$VERSION"
KRAWLER_TAG=$KRAWLER_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 (job.Dockerfile.dockerignore)
DOCKER_BUILDKIT=1 docker build \
--build-arg KRAWLER_TAG=$KRAWLER_TAG \
-f dockerfile."$JOB_VARIANT" \
-t "$IMAGE_NAME:$IMAGE_TAG" \
"$WORKSPACE_DIR/$JOB"

if [ "$PUBLISH" = true ]; then
docker push "$IMAGE_NAME:$IMAGE_TAG"
fi

docker logout

end_group "Building container ..."
build_job \
"$ROOT_DIR" \
"kalisio" \
"$JOB_VARIANT" \
"$KALISIO_DOCKERHUB_URL" \
"$KALISIO_DOCKERHUB_USERNAME" \
"$KALISIO_DOCKERHUB_PASSWORD" \
"$PUBLISH"
24 changes: 4 additions & 20 deletions scripts/setup_workspace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ ROOT_DIR=$(dirname "$THIS_DIR")

. "$THIS_DIR/kash/kash.sh"

## Parse options
##

WORKSPACE_BRANCH=
WORKSPACE_TAG=

begin_group "Setting up workspace ..."

if [ "$CI" = true ]; then
Expand All @@ -32,23 +26,13 @@ else
done
shift $((OPTIND-1))
WORKSPACE_DIR="$1"

# NOTE: cloning krawler could be avoided if we could parse app_version from tag/branch name instead
# In this case, the kli would clone krawler
GIT_OPS="--recurse-submodules"
if [ -n "$WORKSPACE_TAG" ] || [ -n "$WORKSPACE_BRANCH" ]; then
GIT_OPS="$GIT_OPS --branch ${WORKSPACE_TAG:-$WORKSPACE_BRANCH}"
fi
git clone --depth 1 $GIT_OPS "$GITHUB_URL/kalisio/k-hubeau.git" "$WORKSPACE_DIR/k-hubeau"

DEVELOPMENT_REPO_URL="$GITHUB_URL/kalisio/development.git"

# unset KALISIO_DEVELOPMENT_DIR because we want kli to clone everything in $WORKSPACE_DIR
unset KALISIO_DEVELOPMENT_DIR
# Clone project in the workspace
git_shallow_clone "$GITHUB_URL/kalisio/k-hubeau.git" "$WORKSPACE_DIR/k-hubeau" "${WORKSPACE_TAG:-${WORKSPACE_BRANCH:-}}"
fi

# clone development in $WORKSPACE_DIR
DEVELOPMENT_DIR="$WORKSPACE_DIR/development"
git clone --depth 1 "$DEVELOPMENT_REPO_URL" "$DEVELOPMENT_DIR"
setup_job_workspace "$WORKSPACE_DIR" "$DEVELOPMENT_REPO_URL"

end_group "Setting up workspace ..."

0 comments on commit a454c31

Please sign in to comment.