Skip to content

Commit 24a8596

Browse files
authored
[CI] Improve Docker image caching by copying app code last (#36)
1 parent 6215457 commit 24a8596

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

.github/workflows/unit_tests.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@ jobs:
1717
uses: docker/setup-buildx-action@v3
1818

1919
- name: Build image
20-
run: make build VERSION=test
20+
uses: docker/build-push-action@v5
21+
with:
22+
context: .
23+
push: false
24+
load: true
25+
tags: |
26+
koreader/kosync:test
27+
koreader/kosync:latest
28+
cache-from: type=gha
29+
cache-to: type=gha,mode=max
2130

2231
- name: Run busted test suite
2332
run: make test VERSION=test

Dockerfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RUN apt-get update \
1010
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
1111

1212
ARG OPENRESTY_VER=1.27.1.2
13-
ENV PATH /opt/openresty/nginx/sbin:$PATH
13+
ENV PATH=/opt/openresty/nginx/sbin:$PATH
1414

1515
WORKDIR /app
1616
RUN wget "https://openresty.org/download/openresty-${OPENRESTY_VER}.tar.gz" \
@@ -25,13 +25,13 @@ RUN mkdir -p /etc/nginx/ssl \
2525
&& openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
2626
-keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt -subj "/"
2727

28-
# add app source code
29-
COPY ./ koreader-sync-server
28+
# copy only the patch needed for the gin build step
29+
COPY gin.patch /tmp/gin.patch
3030

3131
# patch gin for https support
3232
RUN git clone https://github.com/ostinelli/gin \
3333
&& cd gin \
34-
&& patch -N -p1 < /app/koreader-sync-server/gin.patch \
34+
&& patch -N -p1 < /tmp/gin.patch \
3535
&& luarocks make --tree=/usr/local \
3636
&& cd .. \
3737
&& rm -rf gin
@@ -59,6 +59,9 @@ RUN mkdir /etc/service/koreader-sync-server \
5959
/etc/service/koreader-sync-server/run \
6060
&& chmod +x /etc/service/koreader-sync-server/run
6161

62+
# add app source code last so app changes don't invalidate dependency layers
63+
COPY ./ koreader-sync-server
64+
6265
VOLUME ["/var/log/redis", "/var/lib/redis"]
6366

6467
EXPOSE 7200

0 commit comments

Comments
 (0)