Skip to content

Commit

Permalink
Cache docker layers
Browse files Browse the repository at this point in the history
  • Loading branch information
andy5995 committed Nov 29, 2024
1 parent 3716502 commit 0192086
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
44 changes: 35 additions & 9 deletions .github/workflows/docker-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,50 @@ jobs:
echo "OWNER_LC=$OWNER_LC" >>${GITHUB_ENV}
echo "IMAGE=ghcr.io/$OWNER_LC/vs-fltk:build-env" >>${GITHUB_ENV}
- name: Install dependencies
run: sudo apt install -y docker-compose

- name: Check if Dockerfile has changed
run: |
FILES=$(git log -1 -p ./ | grep +++ | cut -d '/' -f 2-| sed -e 's|dev/null||g')
if echo "$FILES" | grep -qE "^(Dockerfile)$"; then
echo "changed=true" >> $GITHUB_ENV
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 "^(Dockerfile)$"; then
echo "do_build=true" >> $GITHUB_ENV
else
echo "do_build=false" >> $GITHUB_ENV
fi
else
echo "changed=false" >> $GITHUB_ENV
# 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.changed == 'true' }}
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
docker compose -f docker/docker-compose.yml run --rm dev
3 changes: 1 addition & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ RUN \
sudo \
swiftlang \
unzip \
wget && \
update-ca-certificates -f
wget

RUN useradd -m builder && passwd -d builder
RUN echo "builder ALL=(ALL) ALL" >> /etc/sudoers
Expand Down

0 comments on commit 0192086

Please sign in to comment.