Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make main workflow reusable #245

Merged
merged 4 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/commit_trigger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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:
DOCKER_USER: ${{ secrets.DOCKER_USER }}
DOCKER_PASS: ${{ secrets.DOCKER_PASS }}
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
KOSLI_API_TOKEN: ${{ secrets.KOSLI_API_TOKEN }}
KOSLI_SONAR_API_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}

27 changes: 23 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,36 @@
name: Main

on:
push:
workflow_call:
inputs:
BASE_IMAGE:
required: true
type: string
KOSLI_TRAIL:
required: true
type: string
secrets:
DOCKER_USER:
required: true
DOCKER_PASS:
required: true
SNYK_TOKEN:
required: true
KOSLI_API_TOKEN:
required: true
KOSLI_SONAR_API_TOKEN:
required: true


env:
CYBER_DOJO_DASHBOARD_BASE_IMAGE: ${{ inputs.BASE_IMAGE }}
KOSLI_CLI_VERSION: ${{ vars.KOSLI_CLI_VERSION }}
KOSLI_DRY_RUN: ${{ vars.KOSLI_DRY_RUN }} # false
KOSLI_HOST: ${{ vars.KOSLI_HOST }} # https://app.kosli.com
KOSLI_API_TOKEN: ${{ secrets.KOSLI_API_TOKEN }}
KOSLI_ORG: ${{ vars.KOSLI_ORG }} # cyber-dojo
KOSLI_FLOW: ${{ vars.KOSLI_FLOW }} # dashboard-ci
KOSLI_TRAIL: ${{ github.sha }}
KOSLI_SONAR_API_TOKEN: ${{ secrets.SONARCLOUD_TOKEN }}
KOSLI_TRAIL: ${{ inputs.KOSLI_TRAIL }}
AWS_ACCOUNT_ID: ${{ vars.AWS_ACCOUNT_ID }}
AWS_ECR_ID: ${{ vars.AWS_ECR_ID }}
AWS_REGION: ${{ vars.AWS_REGION }}
Expand Down Expand Up @@ -165,7 +184,7 @@ jobs:

- name: Run SonarCloud scan
env:
SONAR_TOKEN: ${{ env.KOSLI_SONAR_API_TOKEN }}
SONAR_TOKEN: ${{ secrets.KOSLI_SONAR_API_TOKEN }}
uses: SonarSource/[email protected]

- name: Setup Kosli CLI
Expand Down
8 changes: 7 additions & 1 deletion bin/lib.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#!/usr/bin/env bash
set -Eeu

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

echo_versioner_env_vars()
{
local -r sha="$(cd "${ROOT_DIR}" && git rev-parse HEAD)"
Expand All @@ -25,7 +31,7 @@ echo_versioner_env_vars()
echo CYBER_DOJO_DASHBOARD_IMAGE="${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/dashboard"

if [[ ! -v CYBER_DOJO_DASHBOARD_BASE_IMAGE ]] ; then
echo CYBER_DOJO_DASHBOARD_BASE_IMAGE=cyberdojo/sinatra-base:db948c1
echo CYBER_DOJO_DASHBOARD_BASE_IMAGE="$(echo_base_image)"
fi
}

Expand Down
Loading