-
Notifications
You must be signed in to change notification settings - Fork 2
78 lines (70 loc) · 2.61 KB
/
docker-test.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
name: Test Build-Env Docker Image
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
on:
workflow_dispatch:
pull_request:
branches: master
paths:
- 'docker/**'
- '!**.md'
- '**docker-test.yml'
jobs:
build-test-env-image:
runs-on: ubuntu-latest
env:
SOURCE_ROOT: ${{ github.workspace }}
ENTRYPOINT: ${{ github.workspace }}/docker/default-entry.sh
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set variables
run: |
OWNER_LC=${GITHUB_REPOSITORY_OWNER,,}
echo "OWNER_LC=$OWNER_LC" >>${GITHUB_ENV}
echo "IMAGE=ghcr.io/$OWNER_LC/vs-fltk:build-env" >>${GITHUB_ENV}
- name: Check if Dockerfile has changed
run: |
if [ "${{ github.ref }}" != "refs/heads/master" ]; then
FILES=$(git log -1 -p ./ | grep +++ | cut -d '/' -f 2-| sed -e 's|dev/null||g')
if echo "$FILES" | grep -qE "^(docker/Dockerfile)$"; then
echo "do_build=true" >> $GITHUB_ENV
else
echo "do_build=false" >> $GITHUB_ENV
fi
else
# If there was a push to trunk, we don't want the docker build
# to run. All the builds in docker.yml will be pushed when *that*
# workflow runs, so we really don't want to be adding extra builds
# that won't become "permanent".
# Theoretically, if changes to Dockerfile are pushed to master, it should
# already have been tested anyway.
#
# That may mean the test will fail if the image don't exist yet
# in the registry or there was a dramatic change in the Dockerfile
# that might break the test that runs via docker compose.
# That's ok for now. We'll see how things go...
echo "do_build=false" >> $GITHUB_ENV
fi
- name: Cache Docker layers
if: ${{ env.do_build == 'true' }}
id: docker-cache
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/.docker/buildx-cache
key: ${{ runner.os }}-docker-${{ github.ref_name }}
restore-keys: |
${{ runner.os }}-docker-
- name: Set up Docker Buildx
if: ${{ env.do_build == 'true' }}
uses: docker/setup-buildx-action@v3
- name: Build Docker image
if: ${{ env.do_build == 'true' }}
run: docker build -t $IMAGE -f docker/Dockerfile ./docker
- name: Run commands in Docker container
run: |
export HOSTUID=$(id -u)
export HOSTGID=$(id -g)
docker compose -f docker/docker-compose.yml run --rm dev