Skip to content

Feat/build docker actions #3

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

Merged
merged 7 commits into from
Sep 26, 2024
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
10 changes: 5 additions & 5 deletions .github/workflows/self-dev.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
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:
runs-on: ubuntu-latest
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:
Expand All @@ -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:
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/self-prod.yml
Original file line number Diff line number Diff line change
@@ -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 }}
29 changes: 29 additions & 0 deletions actions/infra-build-images/action.yml
Original file line number Diff line number Diff line change
@@ -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 }}'
31 changes: 31 additions & 0 deletions scripts/build-docker-actions.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions scripts/count-lines.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
set -x
# set -x

TARGET_DIR=$1
IGNORE_RULE=$2
Expand Down Expand Up @@ -44,7 +44,6 @@ case "$IGNORE_RULE" in
;;
esac

echo $GITHUB_OUTPUT >&2
echo "line_count=$line_count" >> $GITHUB_OUTPUT

popd