diff --git a/.github/workflows/self-dev.yml b/.github/workflows/self-dev.yml index 9ed19cb..e2d8ab1 100644 --- a/.github/workflows/self-dev.yml +++ b/.github/workflows/self-dev.yml @@ -1,18 +1,18 @@ -name: Developer workflow +name: CI on: pull_request: push: branches: - main - workflow_call: + workflow_dispatch: inputs: repo: type: string required: false env: - COUNT_LINES_REPO: ${{ inputs.repo || 'kir-dev/cmsch' }} + TARGET_REPO: ${{ inputs.repo || 'kir-dev/cmsch' }} jobs: count-lines: @@ -20,7 +20,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - repository: ${{ env.COUNT_LINES_REPO }} + repository: ${{ env.TARGET_REPO }} - uses: kir-dev/automations/actions/count-lines@main id: counter with: @@ -34,7 +34,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - repository: ${{ env.COUNT_LINES_REPO }} + repository: ${{ env.TARGET_REPO }} - uses: kir-dev/automations/actions/count-lines-docker@main id: counter with: diff --git a/.github/workflows/self-prod.yml b/.github/workflows/self-prod.yml new file mode 100644 index 0000000..6538a8b --- /dev/null +++ b/.github/workflows/self-prod.yml @@ -0,0 +1,54 @@ +name: Deployment + +on: + push: + branches: + - main + workflow_dispatch: + inputs: + environment: + description: 'Select the environment to deploy' + required: true + type: choice + options: + - staging + - production + +jobs: + depoy: + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + + strategy: + matrix: + environment: ${{ fromJson( + github.event_name == 'workflow_dispatch' && '[${{ inputs.environment }}]' || '["staging", "production"]') }} + max-parallel: 1 + + environment: ${{ matrix.environment }} + + env: + DOCKER_TAG: ${{ matrix.environment == 'production' && 'latest' || 'edge' }} + DOCKER_REGISTRY: ghcr.io + DOCKER_NAMESPACE: ${{ github.repository_owner }} + DOCKER_EXTRA_ARGS: --label org.opencontainers.image.source=https://github.com/${{ github.repository }} --cache-from type=gha,mode=max --cache-to type=gha,mode=max + + steps: + - uses: actions/checkout@v4 + + - name: Log into registry ${{ env.DOCKER_REGISTRY }} + uses: docker/login-action@v3 + with: + registry: ${{ env.DOCKER_REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - uses: ./actions/infra-build-images + with: + registry: ${{ env.DOCKER_REGISTRY }} + namespace: ${{ env.DOCKER_NAMESPACE }} + docker-tag: ${{ env.DOCKER_TAG }} + extra-args: --push ${{ env.DOCKER_EXTRA_ARGS }} diff --git a/actions/infra-build-images/action.yml b/actions/infra-build-images/action.yml new file mode 100644 index 0000000..ddb5fb1 --- /dev/null +++ b/actions/infra-build-images/action.yml @@ -0,0 +1,29 @@ +name: A.I.M.A. +description: Automation Images Manager Action +inputs: + registry: + required: true + description: 'The docker registry to use' + namespace: + required: true + description: "Prefix of the docker image name" + docker-tag: + required: true + description: 'Docker tag to assign to the image' + extra-args: + default: '' + description: 'Extra args to pass to docker build' + command_path: + description: "Path to the script that will be executed" + required: true + default: $GITHUB_ACTION_PATH/../../scripts +runs: + using: "composite" + steps: + - uses: docker/setup-buildx-action@v3 + - shell: bash + run: | + ${{ inputs.command_path }}/build-docker-actions.sh \ + ${{ inputs.registry }}/${{ inputs.namespace }} \ + ${{ inputs.docker-tag }} \ + '${{ inputs.extra-args }}' diff --git a/scripts/build-docker-actions.sh b/scripts/build-docker-actions.sh new file mode 100755 index 0000000..d60dd6c --- /dev/null +++ b/scripts/build-docker-actions.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +set -euo pipefail +# set -x + +CONTEXT=$(dirname $0) +DOCKER_REPO=$1 +TAG=$2 +EXTRA_ARGS=${3:-''} + +# Enable this script to be executed locally +: ${GITHUB_OUTPUT:=/dev/stdout} +: ${GITHUB_STATE:=/dev/stdout} +: ${GITHUB_STEP_SUMMARY:=/dev/stdout} +: ${GITHUB_ENV:=/tmp/.github-env} + +pushd $CONTEXT + +for FILE in *.Dockerfile +do + NAME=${FILE%.Dockerfile} + docker buildx build --load \ + --file "$FILE" \ + --tag "$DOCKER_REPO/$NAME:$TAG" \ + $EXTRA_ARGS \ + . +done + +echo '# Docker images' >> $GITHUB_STEP_SUMMARY +docker images "$DOCKER_REPO"/"$NAME"* >> $GITHUB_STEP_SUMMARY + +popd \ No newline at end of file diff --git a/scripts/count-lines.sh b/scripts/count-lines.sh index 894bfa8..987d024 100755 --- a/scripts/count-lines.sh +++ b/scripts/count-lines.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -euo pipefail -set -x +# set -x TARGET_DIR=$1 IGNORE_RULE=$2 @@ -44,7 +44,6 @@ case "$IGNORE_RULE" in ;; esac -echo $GITHUB_OUTPUT >&2 echo "line_count=$line_count" >> $GITHUB_OUTPUT popd \ No newline at end of file