Skip to content

Commit a6c9971

Browse files
committed
docker build-with-cache action
1 parent e0b4890 commit a6c9971

File tree

3 files changed

+107
-62
lines changed

3 files changed

+107
-62
lines changed

.github/workflows/main.yml

Lines changed: 105 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ env:
66
CACHE_IMAGE: fmrcampos/docker-ci-cache
77
GPR_CACHE_IMAGE: docker.pkg.github.com/${{ github.repository }}/docker-ci-cache
88
CACHE_SEED: 1
9+
DOCKER_BUILDKIT: 1
910
NODE_VERSION: 14.4.0
1011

1112
jobs:
1213
test:
1314
runs-on: ubuntu-latest
14-
container: fmrcampos/docker-ci-cache:stage
1515
services:
1616
postgres:
1717
image: postgres:10.1
@@ -20,14 +20,28 @@ jobs:
2020
--health-interval 10s
2121
--health-timeout 5s
2222
--health-retries 5
23+
ports:
24+
# Maps tcp port 5432 on service container to the host
25+
- 5432:5432
2326
steps:
2427
- name: Check out repository
2528
uses: actions/checkout@v2
2629

30+
- uses: whoan/docker-build-with-cache-action@master
31+
with:
32+
image_name: ${{ env.CACHE_IMAGE }}
33+
image_tag: stage
34+
build_extra_args: "--cache-from ${{ env.CACHE_IMAGE }}:static --cache-from ${{ env.CACHE_IMAGE }}:build --cache-from ${{ env.CACHE_IMAGE }}:stage --build-arg BUILDKIT_INLINE_CACHE=1"
35+
push_image_and_stages: false
36+
37+
- uses: actions/setup-python@v2
38+
with:
39+
python-version: 3.8
40+
2741
- name: Cache pip dependencies
2842
uses: actions/cache@v2
2943
env:
30-
cache-name: cache-pip-deps-dh
44+
cache-name: cache-pip-tests-warehouse-p
3145
with:
3246
path: ./.cache/pip
3347
key: ${{ runner.os }}-${{ env.CACHE_SEED }}-${{ github.job }}-${{ env.cache-name }}-${{ hashFiles('requirements.txt') }}
@@ -68,24 +82,16 @@ jobs:
6882
${{ runner.os }}-
6983
7084
- name: Install dependencies
71-
run: |
72-
apt-get update && apt-get -y install make locales build-essential curl libpq-dev autoconf
73-
apt -y install libcurl4-openssl-dev libssl-dev pkg-config
74-
75-
- name: Set locale
76-
run: |
77-
echo "LC_ALL=en_US.UTF-8" >> /etc/environment
78-
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
79-
echo "LANG=en_US.UTF-8" > /etc/locale.conf
80-
locale-gen en_US.UTF-8
85+
run: sudo apt -y install libcurl4-openssl-dev libssl-dev pkg-config
8186

8287
- name: Install pip requirements
8388
run: |
8489
mkdir ./.cache && mkdir ./.cache/pip
8590
chown -R $(whoami) ./.cache/pip
8691
pip install -U pip setuptools wheel --cache-dir ./.cache/pip
87-
pip install -r requirements.txt --cache-dir ./.cache/pip
88-
pip install -r requirements/dev.txt --cache-dir ./.cache/pip
92+
pip install -r requirements/main.txt --cache-dir ./.cache/pip
93+
pip install -r requirements/tests.txt --cache-dir ./.cache/pip
94+
pip install -r requirements/deploy.txt --cache-dir ./.cache/pip
8995
9096
- name: Setup node
9197
run: |
@@ -100,105 +106,148 @@ jobs:
100106
101107
- name: Run tests
102108
run: |
103-
python -m coverage run -m pytest --strict --postgresql-host postgres
109+
python -m coverage run -m pytest --strict --postgresql-host localhost
104110
python -m coverage html
105111
python -m coverage report -m --fail-under 100
106112
env:
107113
# The hostname used to communicate with the PostgreSQL service container
108-
POSTGRES_HOST: postgres
114+
POSTGRES_HOST: localhost
109115
# The default PostgreSQL port
110116
POSTGRES_PORT: 5432
111117

112118
lint:
113119
runs-on: ubuntu-latest
114-
container: fmrcampos/docker-ci-cache:stage
115120
steps:
116121
- name: Check out repository
117122
uses: actions/checkout@v2
118123

124+
- uses: whoan/docker-build-with-cache-action@master
125+
with:
126+
image_name: ${{ env.CACHE_IMAGE }}
127+
image_tag: stage
128+
build_extra_args: "--cache-from ${{ env.CACHE_IMAGE }}:static --cache-from ${{ env.CACHE_IMAGE }}:build --cache-from ${{ env.CACHE_IMAGE }}:stage --build-arg BUILDKIT_INLINE_CACHE=1"
129+
push_image_and_stages: false
130+
119131
- uses: actions/setup-python@v2
120132
with:
121133
python-version: 3.8
122134

123135
- name: Lint
124136
run: |
125-
apt-get update && apt-get install make
137+
sudo apt-get update && sudo apt-get install make
126138
make lint ACTIONS=true
127139
128140
docs:
129141
runs-on: ubuntu-latest
130-
container: fmrcampos/docker-ci-cache:stage
131142
steps:
132143
- name: Check out repository
133144
uses: actions/checkout@v2
134145

146+
- uses: whoan/docker-build-with-cache-action@master
147+
with:
148+
image_name: ${{ env.CACHE_IMAGE }}
149+
image_tag: stage
150+
build_extra_args: "--cache-from ${{ env.CACHE_IMAGE }}:static --cache-from ${{ env.CACHE_IMAGE }}:build --cache-from ${{ env.CACHE_IMAGE }}:stage --build-arg BUILDKIT_INLINE_CACHE=1"
151+
push_image_and_stages: false
152+
153+
- uses: actions/setup-python@v2
154+
with:
155+
python-version: 3.8
156+
135157
- name: Documentation
136158
run: |
137-
apt-get update && apt-get install make
159+
sudo apt-get update && sudo apt-get install make
138160
make docs
139161
140162
deps:
141163
runs-on: ubuntu-latest
142-
container: fmrcampos/docker-ci-cache:stage
143164
steps:
144165
- name: Check out repository
145166
uses: actions/checkout@v2
146167

168+
- uses: whoan/docker-build-with-cache-action@master
169+
with:
170+
image_name: ${{ env.CACHE_IMAGE }}
171+
image_tag: stage
172+
build_extra_args: "--cache-from ${{ env.CACHE_IMAGE }}:static --cache-from ${{ env.CACHE_IMAGE }}:build --cache-from ${{ env.CACHE_IMAGE }}:stage --build-arg BUILDKIT_INLINE_CACHE=1"
173+
push_image_and_stages: false
174+
175+
- uses: actions/setup-python@v2
176+
with:
177+
python-version: 3.8
178+
147179
- name: Cache pip dependencies
148180
uses: actions/cache@v2
149181
env:
150-
cache-name: cache-pip-deps-dh
182+
cache-name: cache-pip-deps-warehouse-p
151183
with:
152-
path: ./.cache/pip
184+
path: ~/.cache/pip
153185
key: ${{ runner.os }}-${{ env.CACHE_SEED }}-${{ github.job }}-${{ env.cache-name }}-${{ hashFiles('requirements.txt') }}
154186
restore-keys: |
155187
${{ runner.os }}-${{ env.CACHE_SEED }}-${{ github.job }}-${{ env.cache-name }}-
156188
${{ runner.os }}-${{ env.CACHE_SEED }}-${{ github.job }}-
157189
${{ runner.os }}-${{ env.CACHE_SEED }}-
158190
${{ runner.os }}-
159191
160-
- name: Install dependencies
192+
- name: Set cache permissions
161193
run: |
162-
apt-get update && apt-get -y install build-essential make libpq-dev
163-
apt -y install libcurl4-openssl-dev libssl-dev pkg-config
164-
mkdir ./.cache && mkdir ./.cache/pip
165-
chown -R $(whoami) ./.cache/pip
166-
pip install -U pip setuptools wheel --cache-dir ./.cache/pip
167-
pip install -r requirements.txt --cache-dir ./.cache/pip
168-
pip install -r requirements/dev.txt --cache-dir ./.cache/pip
194+
mkdir ~/.cache && mkdir ~/.cache/pip
195+
chown -R $(whoami) ~/.cache/pip
169196
170197
- name: Check dependencies
171-
run: make deps
198+
run: |
199+
sudo apt -y install libcurl4-openssl-dev libssl-dev pkg-config
200+
make deps
172201
173202
licenses:
174203
runs-on: ubuntu-latest
175-
container: fmrcampos/docker-ci-cache:stage
176204
steps:
177205
- name: Check out repository
178206
uses: actions/checkout@v2
179207

208+
- uses: whoan/docker-build-with-cache-action@master
209+
with:
210+
image_name: ${{ env.CACHE_IMAGE }}
211+
image_tag: stage
212+
build_extra_args: "--cache-from ${{ env.CACHE_IMAGE }}:static --cache-from ${{ env.CACHE_IMAGE }}:build --cache-from ${{ env.CACHE_IMAGE }}:stage --build-arg BUILDKIT_INLINE_CACHE=1"
213+
push_image_and_stages: false
214+
180215
- name: Check licenses
181216
run: bin/licenses
182217

183218
translations:
184219
runs-on: ubuntu-latest
185-
container: fmrcampos/docker-ci-cache:stage
186220
steps:
187221
- name: Check out repository
188222
uses: actions/checkout@v2
189223

224+
- uses: whoan/docker-build-with-cache-action@master
225+
with:
226+
image_name: ${{ env.CACHE_IMAGE }}
227+
image_tag: stage
228+
build_extra_args: "--cache-from ${{ env.CACHE_IMAGE }}:static --cache-from ${{ env.CACHE_IMAGE }}:build --cache-from ${{ env.CACHE_IMAGE }}:stage --build-arg BUILDKIT_INLINE_CACHE=1"
229+
push_image_and_stages: false
230+
231+
- uses: actions/setup-python@v2
232+
with:
233+
python-version: 3.8
234+
190235
- name: Check translations
191-
run: |
192-
apt-get update && apt-get -y install make
193-
make translations
236+
run: make translations
194237

195238
static-lint:
196239
runs-on: ubuntu-latest
197-
container: fmrcampos/docker-ci-cache:static
198240
steps:
199241
- name: Check out repository
200242
uses: actions/checkout@v2
201243

244+
- uses: whoan/docker-build-with-cache-action@master
245+
with:
246+
image_name: ${{ env.CACHE_IMAGE }}
247+
image_tag: static
248+
build_extra_args: "--target static --cache-from ${{ env.CACHE_IMAGE }}:static --build-arg BUILDKIT_INLINE_CACHE=1"
249+
push_image_and_stages: false
250+
202251
- name: Static Lint Check
203252
run: |
204253
npm install eslint --save-dev
@@ -207,11 +256,17 @@ jobs:
207256
208257
static-tests:
209258
runs-on: ubuntu-latest
210-
container: fmrcampos/docker-ci-cache:static
211259
steps:
212260
- name: Check out repository
213261
uses: actions/checkout@v2
214262

263+
- uses: whoan/docker-build-with-cache-action@master
264+
with:
265+
image_name: ${{ env.CACHE_IMAGE }}
266+
image_tag: static
267+
build_extra_args: "--target static --cache-from ${{ env.CACHE_IMAGE }}:static --build-arg BUILDKIT_INLINE_CACHE=1"
268+
push_image_and_stages: false
269+
215270
- name: Cache node modules
216271
uses: actions/cache@v2
217272
env:
@@ -228,25 +283,25 @@ jobs:
228283
${{ runner.os }}-build-
229284
${{ runner.os }}-
230285
231-
- name: Locale & Dependency Setup
232-
run: |
233-
apt-get update && apt-get -y install locales
234-
echo "LC_ALL=en_US.UTF-8" >> /etc/environment
235-
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
236-
echo "LANG=en_US.UTF-8" > /etc/locale.conf
237-
locale-gen en_US.UTF-8
238-
npm install -D babel
286+
- name: Dependency Setup
287+
run: npm install -D babel
239288

240289
- name: Static Tests
241290
run: bin/static_tests
242291

243292
static-pipeline:
244293
runs-on: ubuntu-latest
245-
container: fmrcampos/docker-ci-cache:static
246294
steps:
247295
- name: Check out repository
248296
uses: actions/checkout@v2
249297

298+
- uses: whoan/docker-build-with-cache-action@master
299+
with:
300+
image_name: ${{ env.CACHE_IMAGE }}
301+
image_tag: static
302+
build_extra_args: "--target static --cache-from ${{ env.CACHE_IMAGE }}:static --build-arg BUILDKIT_INLINE_CACHE=1"
303+
push_image_and_stages: false
304+
250305
- name: Cache node version manager
251306
uses: actions/cache@v2
252307
env:
@@ -277,14 +332,8 @@ jobs:
277332
${{ runner.os }}-build-
278333
${{ runner.os }}-
279334
280-
- name: Locale & Dependency Setup
281-
run: |
282-
apt-get update && apt-get -y install locales
283-
echo "LC_ALL=en_US.UTF-8" >> /etc/environment
284-
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
285-
echo "LANG=en_US.UTF-8" > /etc/locale.conf
286-
locale-gen en_US.UTF-8
287-
npm install -D babel
335+
- name: Dependency Setup
336+
run: npm install -D babel
288337

289338
- name: Static Pipeline Check
290339
run: bin/static_pipeline

.github/workflows/registry.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ name: Registry Image Caching
33
on:
44
push:
55
branches:
6-
- master
6+
- github-actions-ci
77

88
env:
99
CACHE_IMAGE: fmrcampos/docker-ci-cache
1010
GPR_CACHE_IMAGE: docker.pkg.github.com/${{ github.repository }}/docker-ci-cache
1111
DOCKER_BUILDKIT: 1
1212

13-
update-cache:
13+
jobs:
1414
build-dh:
1515
name: Docker Hub Cache
1616
runs-on: ubuntu-latest
@@ -71,7 +71,6 @@ update-cache:
7171
--cache-from $GPR_CACHE_IMAGE:static \
7272
--tag $GPR_CACHE_IMAGE:static \
7373
--file ./Dockerfile \
74-
# can't use BuildKit for GPR
7574
"."
7675
- name: Build build image from Dockerfile
7776
run: |
@@ -82,7 +81,6 @@ update-cache:
8281
--cache-from $GPR_CACHE_IMAGE:build \
8382
--tag $GPR_CACHE_IMAGE:build \
8483
--file ./Dockerfile \
85-
# can't use BuildKit for GPR
8684
"."
8785
- name: Build stage image from Dockerfile
8886
run: |
@@ -92,7 +90,6 @@ update-cache:
9290
--cache-from $GPR_CACHE_IMAGE:stage \
9391
--tag $GPR_CACHE_IMAGE:stage \
9492
--file ./Dockerfile \
95-
# can't use BuildKit for GPR
9693
"."
9794
- name: Push static image to package registry
9895
run: docker push $GPR_CACHE_IMAGE:static

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ RUN set -x \
3535
COPY warehouse/static/ /opt/warehouse/src/warehouse/static/
3636
COPY warehouse/admin/static/ /opt/warehouse/src/warehouse/admin/static/
3737
COPY Gulpfile.babel.js /opt/warehouse/src/
38-
COPY tests/frontend .sass-lint.yml /opt/warehouse/src/
3938

4039
RUN gulp dist
4140

0 commit comments

Comments
 (0)