Skip to content

Commit 10e5a32

Browse files
committed
ci: save and reuse docker and build cache
Signed-off-by: Maxim Eryomenko <[email protected]>
1 parent a4eeae8 commit 10e5a32

File tree

3 files changed

+96
-52
lines changed

3 files changed

+96
-52
lines changed

.github/workflows/dockerimage.yml

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,60 @@ jobs:
1515
build:
1616
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/checkout@v1
19-
- name: Build the Docker image
20-
run: docker build . -t build
21-
- name: Testing image
22-
shell: bash
23-
working-directory: tests
24-
run: |
25-
docker build . -t test
26-
docker run -d -p 8080:80 -p 8083:83 test
27-
./test.sh
28-
docker stop $(docker ps -aq)
29-
- name: Push the Docker image
30-
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
31-
run: |
32-
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
33-
function tag_and_push {
34-
docker tag build "moeryomenko/ngxjs:${1}" && docker push "moeryomenko/ngxjs:${1}"
35-
}
36-
if [[ "${GITHUB_REF}" == "refs/heads/master" ]]; then
37-
tag_and_push "development"
38-
elif [[ "${GITHUB_REF}" =~ refs/tags/v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
18+
- name: Checkout
19+
uses: actions/checkout@v2
20+
# This is the a separate action that sets up buildx runner
21+
- name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v1
23+
# So now you can use Actions' own caching!
24+
- name: Cache Docker layers
25+
uses: actions/cache@v2
26+
with:
27+
path: /tmp/.buildx-cache
28+
key: ${{ runner.os }}-buildx-${{ github.sha }}
29+
restore-keys: |
30+
${{ runner.os }}-buildx-
31+
- name: Login to DockerHub
32+
uses: docker/login-action@v1
33+
with:
34+
username: ${{ secrets.DOCKER_USERNAME }}
35+
password: ${{ secrets.DOCKER_PASSWORD }}
36+
# And make it available for the builds
37+
- name: Build and push
38+
uses: docker/build-push-action@v2
39+
with:
40+
context: .
41+
push: false
42+
tags: moeryomenko/ngxjs:latest
43+
cache-from: type=local,src=/tmp/.buildx-cache
44+
cache-to: type=local,dest=/tmp/.buildx-cache-new
45+
# This ugly bit is necessary if you don't want your cache to grow forever
46+
# till it hits GitHub's limit of 5GB.
47+
# Temp fix
48+
# https://github.com/docker/build-push-action/issues/252
49+
# https://github.com/moby/buildkit/issues/1896
50+
- name: Move cache
51+
run: |
52+
rm -rf /tmp/.buildx-cache
53+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
54+
- name: Testing image
55+
shell: bash
56+
working-directory: tests
57+
run: |
58+
docker build . -t test
59+
docker run -d -p 8080:80 -p 8083:83 test
60+
./test.sh
61+
docker stop $(docker ps -aq)
62+
- name: Push the Docker image
63+
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
64+
run: |
65+
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
66+
function tag_and_push {
67+
docker tag moeryomenko/ngxjs "moeryomenko/ngxjs:${1}" && docker push "moeryomenko/ngxjs:${1}"
68+
}
69+
if [[ "${GITHUB_REF}" == "refs/heads/master" ]]; then
70+
tag_and_push "development"
71+
elif [[ "${GITHUB_REF}" =~ refs/tags/v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
3972
TAG="${GITHUB_REF#"refs/tags/v"}"
4073
tag_and_push "${TAG}"
4174
if [[ "${TAG}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
@@ -47,6 +80,6 @@ jobs:
4780
tag_and_push "${TAG%.*.*}-ttn";
4881
tag_and_push "latest-ttn"
4982
fi
50-
else
51-
tag_and_push "${GITHUB_REF#"refs/tags/"}"
52-
fi
83+
else
84+
tag_and_push "${GITHUB_REF#"refs/tags/"}"
85+
fi

Dockerfile

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,54 @@
22
# Default to Go 1.16.
33
ARG GO_VERSION=1.17
44

5-
FROM golang:${GO_VERSION}-alpine as build
5+
FROM golang:${GO_VERSION}-alpine3.14 as base
66

77
LABEL maintainer="Maxim Eryomenko <[email protected]>"
88

9-
ENV NGINX_VERSION 1.21.3
9+
ENV NGINX_VERSION 1.21.4
1010
ENV NJS_VERSION 0.6.2
11-
ENV CFLAGS "-O2"
12-
ENV CXXFLAGS "-O2"
11+
ENV CFLAGS "-O3"
12+
ENV CXXFLAGS "-O3"
1313

14-
RUN apk add --no-cache \
15-
gcc libc-dev autoconf libtool automake \
14+
RUN apk add --no-cache gcc libc-dev \
15+
autoconf libtool automake \
1616
make cmake ninja pcre-dev \
17-
linux-headers libxslt-dev gd-dev geoip-dev \
18-
perl-dev libedit-dev git alpine-sdk findutils \
19-
libunwind-dev curl tar
17+
linux-headers libxslt-dev gd-dev \
18+
geoip-dev perl-dev libedit-dev \
19+
git alpine-sdk findutils \
20+
libunwind-dev curl tar ccache clang
21+
22+
FROM base as build
2023

2124
WORKDIR /src
2225

23-
RUN git clone --depth 1 --branch 2.0.5 https://github.com/zlib-ng/zlib-ng.git \
24-
&& cd zlib-ng \
25-
&& cmake -DZLIB_COMPAT=ON -DZLIB_ENABLE_TESTS=OFF -DCMAKE_BUILD_TYPE=Release .\
26-
&& cmake --build . \
27-
&& cmake --build . --target install
26+
RUN --mount=type=cache,target=/root/.cache/ccache \
27+
git clone --depth 1 --branch 2.0.5 https://github.com/zlib-ng/zlib-ng.git && \
28+
cd zlib-ng && \
29+
cmake -GNinja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
30+
-DCMAKE_C_COMPILER_LAUNCHER='/usr/bin/ccache' \
31+
-DCMAKE_CXX_COMPILER_LAUNCHER='/usr/bin/ccache' \
32+
-DZLIB_COMPAT=ON -DZLIB_ENABLE_TESTS=OFF -DCMAKE_BUILD_TYPE=Release . && \
33+
cmake --build . && \
34+
cmake --build . --target install
2835

2936
# Build BoringSSL.
30-
RUN git clone https://boringssl.googlesource.com/boringssl \
31-
&& cd boringssl \
32-
&& mkdir build \
33-
&& cd build \
34-
&& cmake -GNinja -DCMAKE_BUILD_TYPE=Release .. \
35-
&& ninja \
36-
&& mkdir -p ../.openssl/lib \
37-
&& cd ../.openssl \
38-
&& ln -s ../include include \
39-
&& cp ../build/crypto/libcrypto.a lib/ \
40-
&& cp ../build/ssl/libssl.a lib/ \
41-
&& cd /src
37+
RUN --mount=type=cache,target=/root/.cache/ccache \
38+
git clone https://boringssl.googlesource.com/boringssl && \
39+
cd boringssl && \
40+
mkdir build && \
41+
cd build && \
42+
cmake -GNinja -DCMAKE_C_COMPILER=clang \
43+
-DCMAKE_CXX_COMPILER=clang++ \
44+
-DCMAKE_C_COMPILER_LAUNCHER='/usr/bin/ccache' \
45+
-DCMAKE_CXX_COMPILER_LAUNCHER='/usr/bin/ccache' -DCMAKE_BUILD_TYPE=Release .. && \
46+
ninja && \
47+
mkdir -p ../.openssl/lib && \
48+
cd ../.openssl && \
49+
ln -s ../include include && \
50+
cp ../build/crypto/libcrypto.a lib/ && \
51+
cp ../build/ssl/libssl.a lib/ && \
52+
cd /src
4253

4354
# Download njs module.
4455
RUN mkdir njs \
@@ -55,7 +66,7 @@ RUN mkdir nginx \
5566
&& curl -SL http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz | tar xz -C nginx --strip-components=1 \
5667
&& cd nginx \
5768
&& ./configure --prefix=/usr/share/nginx \
58-
--sbin-path=/usr/bin/nginx \
69+
--sbin-path=/usr/bin/nginx \
5970
--conf-path=/etc/nginx/nginx.conf \
6071
--error-log-path=/var/log/nginx/error.log \
6172
--http-log-path=/var/log/nginx/access.log \

tests/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM build
1+
FROM moeryomenko/ngxjs:latest
22

33
COPY assets /usr/share/nginx/html
44
COPY etc /etc

0 commit comments

Comments
 (0)