diff --git a/.github/workflows/commit_trigger.yml b/.github/workflows/commit_trigger.yml new file mode 100644 index 0000000..d8d9854 --- /dev/null +++ b/.github/workflows/commit_trigger.yml @@ -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 }} + diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 10d7faa..8c6f842 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 }} @@ -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 @@ -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()) }} @@ -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()) }} @@ -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 @@ -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 diff --git a/LICENSE.md b/LICENSE.md index 1b8411d..e34262b 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -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 diff --git a/bin/build_image.sh b/bin/build_image.sh index 142309f..34c65aa 100755 --- a/bin/build_image.sh +++ b/bin/build_image.sh @@ -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 } diff --git a/bin/lib.sh b/bin/lib.sh index 9681b57..09c00d2 100644 --- a/bin/lib.sh +++ b/bin/lib.sh @@ -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)" @@ -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() @@ -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 diff --git a/docs/api.md b/docs/api.md index 8254eac..8a37c78 100644 --- a/docs/api.md +++ b/docs/api.md @@ -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 `'{}'`. - - - -