Skip to content

Commit 40876ac

Browse files
committed
ci: Add composite actions
1 parent df0ae7b commit 40876ac

3 files changed

Lines changed: 128 additions & 0 deletions

File tree

.github/actions/docker-build.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Docker build action
2+
description: Composite action for building Devito Docker containers
3+
author: "Devito"
4+
5+
inputs:
6+
# The only supported GHA input type is string
7+
file:
8+
description: "Dockerfile containing build instructions"
9+
required: true
10+
default: Dockerfile
11+
tag:
12+
description: "Tag to add to the built image"
13+
required: true
14+
base:
15+
description: "Base docker image to build on top of"
16+
required: true
17+
18+
outputs:
19+
unique:
20+
description: "Unique identifier for the CI run"
21+
value: ${{ steps.uniquetag.unique }}
22+
23+
runs:
24+
using: "composite"
25+
steps:
26+
- id: uniquetag
27+
name: "Generate unique CI tag"
28+
run: |
29+
UNIQUE=$(echo "${GITHUB_RUN_ID}_${GITHUB_RUN_ATTEMPT}" | cksum | cut -f 1 -d " ")
30+
echo "Unique ID: ${UNIQUE}"
31+
echo "unique=${UNIQUE}" >> "$GITHUB_OUTPUT"
32+
33+
- id: dockerbuild
34+
name: "Build docker container"
35+
run: >
36+
docker build
37+
--pull
38+
--file ${{ inputs.file }}
39+
--tag ${{ inputs.tag }}${{ steps.uniquetag.unique }}
40+
--build-arg base=${{ inputs.base }}
41+
.
42+
43+
# Do we need to be more specific?
44+
#~ docker buildx build . \
45+
#~ --builder "${RUNNER_NAME// /_}" \
46+
#~ --load \
47+
#~ --label ci-run="$GITHUB_RUN_ID" \
48+
#~ --rm --pull \
49+
#~ --file docker/Dockerfile.devito \
50+
#~ --tag "${DOCKER_IMAGE}" \
51+
#~ --build-arg base="${{ matrix.base }}"

.github/actions/docker-clean.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Docker run action
2+
description: Reusable workflow for running commands in Docker containers
3+
author: "Devito"
4+
5+
inputs:
6+
# The only supported GHA input type is string
7+
id:
8+
description: "Unique identifier output from docker-build action"
9+
required: true
10+
tag:
11+
description: "Tag of the built image to use"
12+
required: true
13+
14+
runs:
15+
using: "composite"
16+
steps:
17+
- id: dockerclean
18+
name: "Cleanup docker image"
19+
run: |
20+
docker image rm -f "${{ inputs.tag }}${{ inputs.id }}"

.github/actions/docker-run.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Docker run action
2+
description: Reusable workflow for running commands in Docker containers
3+
author: "Devito"
4+
5+
inputs:
6+
# The only supported GHA input type is string
7+
id:
8+
description: "Unique identifier output from docker-build action"
9+
required: true
10+
args:
11+
description: "Arguments to pass to `docker run`"
12+
required: true
13+
default: Dockerfile
14+
env:
15+
description: "Environment variables to set inside the docker container"
16+
required: true
17+
default: Dockerfile
18+
tag:
19+
description: "Tag of the built image to use"
20+
required: true
21+
command:
22+
description: "Command to execute inside of the docker container"
23+
required: true
24+
25+
outputs:
26+
unique:
27+
description: "Unique identifier for the CI run"
28+
value: ${{ steps.uniquetag.unique }}
29+
30+
runs:
31+
using: "composite"
32+
steps:
33+
- id: processenv
34+
name: Process environment variable list
35+
env:
36+
ENV_INPUT: ${{ inputs.env }}
37+
run: |
38+
ENV_STRING=""
39+
# Read line by line with here string, safely handling spaces within the values
40+
while IFS= read -r LINE; do
41+
if [[ -n "$line" ]]; then
42+
ENV_STRING="$ENV_STRING --env $LINE"
43+
fi
44+
done <<< "$ENV_INPUT"
45+
# Remove the leading space from the first concatenation
46+
ENV_STRING="${ENV_STRING# }"
47+
echo "env=$ENV_STRING" >> "$GITHUB_OUTPUT
48+
49+
- id: dockerrun
50+
name: "Run command ${{ input.command }} in ${{ input.tag }} docker container"
51+
run: >
52+
docker run
53+
--init -t --rm
54+
--name "${{ input.name }}${{ input.id }}"
55+
${{ steps.processenv.outputs.env }}
56+
"${{ input.tag }}${{ input.id }}"
57+
${{ input.command }}

0 commit comments

Comments
 (0)