-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (53 loc) · 2.01 KB
/
build-container.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
name: Build and Publish Docker Containers
on:
push:
branches:
- main
paths:
- 'environments/**/Dockerfile'
- 'pyproject.toml'
workflow_dispatch:
permissions:
contents: write
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
ENVIRONMENTS_DIR: environments
jobs:
build-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Extract commit SHA
run: echo "SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Find Docker Directories
id: find-docker-dirs
run: |
docker_dirs=$(find $ENVIRONMENTS_DIR -type f -name Dockerfile -exec dirname {} \;)
echo "DOCKER_DIRS<<EOF" >> $GITHUB_ENV
echo "${docker_dirs}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
# This should be docker compose or something
- name: Build and Push Docker Images
run: |
while IFS= read -r dir; do
if [[ -n "$dir" ]]; then
dockerfile="./$dir/Dockerfile"
image_name=$(basename "$dir") # Extracts the name of the directory
docker build -f "$dockerfile" -t ${{ env.REGISTRY }}/${{ github.repository_owner }}/$image_name:latest .
docker push ${{ env.REGISTRY }}/${{ github.repository_owner }}/$image_name:latest
# tag the image with the short SHA
docker tag ${{ env.REGISTRY }}/${{ github.repository_owner }}/$image_name:latest ${{ env.REGISTRY }}/${{ github.repository_owner }}/$image_name:${{ env.SHORT_SHA }}
docker push ${{ env.REGISTRY }}/${{ github.repository_owner }}/$image_name:${{ env.SHORT_SHA }}
fi
done <<< "$DOCKER_DIRS"
env:
DOCKER_BUILDKIT: 1