Skip to content

Commit

Permalink
Make main workflow reusable
Browse files Browse the repository at this point in the history
  • Loading branch information
JonJagger committed Jan 20, 2025
1 parent a3481eb commit 8820c47
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 17 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/commit_trigger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Pushed Commit

on:
push:


jobs:
get-base-image:
runs-on: ubuntu-latest
outputs:
base_image: ${{ steps.vars.outputs.base_image }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Output the base-image
id: vars
run: |
source ./bin/lib.sh
echo "base_image=$(echo_base_image)" >> ${GITHUB_OUTPUT}
trigger:
needs: [get-base-image]
uses: ./.github/workflows/main.yml
with:
BASE_IMAGE: ${{ needs.get-base-image.outputs.base_image }}
KOSLI_TRAIL: ${{ github.sha }}
secrets:
KOSLI_API_TOKEN: ${{ secrets.KOSLI_API_TOKEN }}

29 changes: 19 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
name: Main

on:
push:
workflow_call:
inputs:
BASE_IMAGE:
required: true
KOSLI_TRAIL:
required: true
secrets:
KOSLI_API_TOKEN:
required: true

env:
CYBER_DOJO_SAVER_BASE_IMAGE: ${{ inputs.BASE_IMAGE }}
KOSLI_API_TOKEN: ${{ secrets.KOSLI_API_TOKEN }}
KOSLI_TRAIL: ${{ inputs.KOSLI_TRAIL }}
KOSLI_DRY_RUN: ${{ vars.KOSLI_DRY_RUN }} # false
KOSLI_HOST: ${{ vars.KOSLI_HOST }} # https://app.kosli.com
KOSLI_ORG: ${{ vars.KOSLI_ORG }} # cyber-dojo
KOSLI_FLOW: ${{ vars.KOSLI_FLOW }} # saver-ci
KOSLI_API_TOKEN: ${{ secrets.KOSLI_API_TOKEN }}
KOSLI_TRAIL: ${{ github.sha }}
SERVICE_NAME: ${{ github.event.repository.name }} # saver
AWS_ACCOUNT_ID: ${{ vars.AWS_ACCOUNT_ID }}
AWS_ECR_ID: ${{ vars.AWS_ECR_ID }}
Expand All @@ -33,7 +42,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
fetch-depth: 1

- name: Prepare outputs for workflow jobs
id: vars
Expand Down Expand Up @@ -223,8 +232,8 @@ jobs:
KOSLI_FINGERPRINT: ${{ needs.build-image.outputs.artifact_digest }}
run:
kosli attest junit
--name=saver.unit-test
--results-dir=./reports/server/junit
--name=saver.unit-test
--results-dir=./reports/server/junit

- name: Attest test metrics to Kosli
if: ${{ github.ref == 'refs/heads/main' && (success() || failure()) }}
Expand Down Expand Up @@ -281,8 +290,8 @@ jobs:
KOSLI_FINGERPRINT: ${{ needs.build-image.outputs.artifact_digest }}
run:
kosli attest junit
--name=saver.integration-test
--results-dir=./reports/client/junit
--name=saver.integration-test
--results-dir=./reports/client/junit

- name: Attest test metrics to Kosli
if: ${{ github.ref == 'refs/heads/main' && (success() || failure()) }}
Expand Down Expand Up @@ -446,7 +455,7 @@ jobs:

# The cyberdojo/versioner refresh-env.sh script
# https://github.com/cyber-dojo/versioner/blob/master/sh/refresh-env.sh
# relies on being able to:
# currently relies on being able to:
# - get the :latest image from dockerhub
# - extract the SHA env-var embedded inside it
# - use the 1st 7 chars of the SHA as a latest-equivalent tag from dockerhub
Expand All @@ -465,7 +474,7 @@ jobs:
role-duration-seconds: 900
role-session-name: ${{ github.event.repository.name }}
role-to-assume: arn:aws:iam::${{ needs.setup.outputs.aws_account_id }}:role/${{ needs.setup.outputs.gh_actions_iam_role_name }}
mask-aws-account-id: 'no'
mask-aws-account-id: no

- name: Login to Amazon ECR
id: login-ecr
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2024, [CyberDojo Foundation](http://blog.cyber-dojo.org/2015/08/cyber-dojo-foundation.html)
Copyright (c) 2025, [CyberDojo Foundation](http://blog.cyber-dojo.org/2015/08/cyber-dojo-foundation.html)
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
4 changes: 2 additions & 2 deletions bin/build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ show_help()
Use: ${MY_NAME} {server|client}
Options:
server - build the server image (local only)
client - build the client image (local and CI workflow)
server - build the server image
client - build the client image
EOF
}
Expand Down
15 changes: 12 additions & 3 deletions bin/lib.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

echo_base_image()
{
local -r json="$(curl --fail --silent --request GET https://beta.cyber-dojo.org/saver/base_image)"
echo "${json}" | jq -r '.base_image'
}

echo_versioner_env_vars()
{
local -r sha="$(cd "${ROOT_DIR}" && git rev-parse HEAD)"
Expand All @@ -21,8 +27,9 @@ echo_versioner_env_vars()
local -r AWS_REGION=eu-central-1
echo CYBER_DOJO_SAVER_IMAGE=${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/saver

local -r json="$(curl --fail --silent --request GET https://beta.cyber-dojo.org/saver/base_image)"
echo CYBER_DOJO_SAVER_BASE_IMAGE="$(echo "${json}" | jq -r '.base_image')"
if [[ ! -v CYBER_DOJO_SAVER_BASE_IMAGE ]] ; then
echo CYBER_DOJO_SAVER_BASE_IMAGE="$(echo_base_image)"
fi
}

stderr()
Expand Down Expand Up @@ -81,7 +88,9 @@ copy_in_saver_test_data()
local -r TEST_DATA_DIR="${ROOT_DIR}/test/server/data"
local -r CID="${CYBER_DOJO_SAVER_SERVER_CONTAINER_NAME}"
# You cannot docker cp to a tmpfs, so tar-piping...
tar --no-xattrs -c -C "${TEST_DATA_DIR}/cyber-dojo" - . | docker exec -i "${CID}" tar x -C /cyber-dojo
set -x
tar -c -C "${TEST_DATA_DIR}/cyber-dojo" - . | docker exec -i "${CID}" tar x -C /cyber-dojo
set +x

local -r tar_files=(
almost_full_group.v0.AWCQdE.tgz
Expand Down
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ The base-image used in the Dockerfile's FROM statement.
- - - -
## JSON in
- All methods pass their argument in a json hash in the http request body.
* For `alive?`,`ready?` and `sha` you can use `''` (which is the default for `curl --data`) instead of `'{}'`.
* For `alive?`,`ready?`, `sha`, and `base_image` you can use `''` (which is the default for `curl --data`) instead of `'{}'`.
- - - -
Expand Down

0 comments on commit 8820c47

Please sign in to comment.