Skip to content

Commit 7eccd3f

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

File tree

3 files changed

+103
-61
lines changed

3 files changed

+103
-61
lines changed

.github/workflows/main.yml

Lines changed: 101 additions & 55 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-deps-warehouse
3145
with:
3246
path: ./.cache/pip
3347
key: ${{ runner.os }}-${{ env.CACHE_SEED }}-${{ github.job }}-${{ env.cache-name }}-${{ hashFiles('requirements.txt') }}
@@ -68,24 +82,15 @@ 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/deploy.txt --cache-dir ./.cache/pip
8994
9095
- name: Setup node
9196
run: |
@@ -100,105 +105,146 @@ jobs:
100105
101106
- name: Run tests
102107
run: |
103-
python -m coverage run -m pytest --strict --postgresql-host postgres
108+
python -m coverage run -m pytest --strict --postgresql-host localhost
104109
python -m coverage html
105110
python -m coverage report -m --fail-under 100
106111
env:
107112
# The hostname used to communicate with the PostgreSQL service container
108-
POSTGRES_HOST: postgres
113+
POSTGRES_HOST: localhost
109114
# The default PostgreSQL port
110115
POSTGRES_PORT: 5432
111116

112117
lint:
113118
runs-on: ubuntu-latest
114-
container: fmrcampos/docker-ci-cache:stage
115119
steps:
116120
- name: Check out repository
117121
uses: actions/checkout@v2
118122

123+
- uses: whoan/docker-build-with-cache-action@master
124+
with:
125+
image_name: ${{ env.CACHE_IMAGE }}
126+
image_tag: stage
127+
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"
128+
push_image_and_stages: false
129+
119130
- uses: actions/setup-python@v2
120131
with:
121132
python-version: 3.8
122133

123134
- name: Lint
124135
run: |
125-
apt-get update && apt-get install make
136+
sudo apt-get update && sudo apt-get install make
126137
make lint ACTIONS=true
127138
128139
docs:
129140
runs-on: ubuntu-latest
130-
container: fmrcampos/docker-ci-cache:stage
131141
steps:
132142
- name: Check out repository
133143
uses: actions/checkout@v2
134144

145+
- uses: whoan/docker-build-with-cache-action@master
146+
with:
147+
image_name: ${{ env.CACHE_IMAGE }}
148+
image_tag: stage
149+
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"
150+
push_image_and_stages: false
151+
152+
- uses: actions/setup-python@v2
153+
with:
154+
python-version: 3.8
155+
135156
- name: Documentation
136157
run: |
137-
apt-get update && apt-get install make
158+
sudo apt-get update && sudo apt-get install make
138159
make docs
139160
140161
deps:
141162
runs-on: ubuntu-latest
142-
container: fmrcampos/docker-ci-cache:stage
143163
steps:
144164
- name: Check out repository
145165
uses: actions/checkout@v2
146166

167+
- uses: whoan/docker-build-with-cache-action@master
168+
with:
169+
image_name: ${{ env.CACHE_IMAGE }}
170+
image_tag: stage
171+
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"
172+
push_image_and_stages: false
173+
174+
- uses: actions/setup-python@v2
175+
with:
176+
python-version: 3.8
177+
147178
- name: Cache pip dependencies
148179
uses: actions/cache@v2
149180
env:
150-
cache-name: cache-pip-deps-dh
181+
cache-name: cache-pip-deps-warehouse
151182
with:
152-
path: ./.cache/pip
183+
path: ~/.cache/pip
153184
key: ${{ runner.os }}-${{ env.CACHE_SEED }}-${{ github.job }}-${{ env.cache-name }}-${{ hashFiles('requirements.txt') }}
154185
restore-keys: |
155186
${{ runner.os }}-${{ env.CACHE_SEED }}-${{ github.job }}-${{ env.cache-name }}-
156187
${{ runner.os }}-${{ env.CACHE_SEED }}-${{ github.job }}-
157188
${{ runner.os }}-${{ env.CACHE_SEED }}-
158189
${{ runner.os }}-
159190
160-
- name: Install dependencies
191+
- name: Set cache permissions
161192
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
193+
mkdir ~/.cache && mkdir ~/.cache/pip
194+
chown -R $(whoami) ~/.cache/pip
169195
170196
- name: Check dependencies
171197
run: make deps
172198

173199
licenses:
174200
runs-on: ubuntu-latest
175-
container: fmrcampos/docker-ci-cache:stage
176201
steps:
177202
- name: Check out repository
178203
uses: actions/checkout@v2
179204

205+
- uses: whoan/docker-build-with-cache-action@master
206+
with:
207+
image_name: ${{ env.CACHE_IMAGE }}
208+
image_tag: stage
209+
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"
210+
push_image_and_stages: false
211+
180212
- name: Check licenses
181213
run: bin/licenses
182214

183215
translations:
184216
runs-on: ubuntu-latest
185-
container: fmrcampos/docker-ci-cache:stage
186217
steps:
187218
- name: Check out repository
188219
uses: actions/checkout@v2
189220

221+
- uses: whoan/docker-build-with-cache-action@master
222+
with:
223+
image_name: ${{ env.CACHE_IMAGE }}
224+
image_tag: stage
225+
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"
226+
push_image_and_stages: false
227+
228+
- uses: actions/setup-python@v2
229+
with:
230+
python-version: 3.8
231+
190232
- name: Check translations
191-
run: |
192-
apt-get update && apt-get -y install make
193-
make translations
233+
run: make translations
194234

195235
static-lint:
196236
runs-on: ubuntu-latest
197-
container: fmrcampos/docker-ci-cache:static
198237
steps:
199238
- name: Check out repository
200239
uses: actions/checkout@v2
201240

241+
- uses: whoan/docker-build-with-cache-action@master
242+
with:
243+
image_name: ${{ env.CACHE_IMAGE }}
244+
image_tag: static
245+
build_extra_args: "--target static --cache-from ${{ env.CACHE_IMAGE }}:static --build-arg BUILDKIT_INLINE_CACHE=1"
246+
push_image_and_stages: false
247+
202248
- name: Static Lint Check
203249
run: |
204250
npm install eslint --save-dev
@@ -207,11 +253,17 @@ jobs:
207253
208254
static-tests:
209255
runs-on: ubuntu-latest
210-
container: fmrcampos/docker-ci-cache:static
211256
steps:
212257
- name: Check out repository
213258
uses: actions/checkout@v2
214259

260+
- uses: whoan/docker-build-with-cache-action@master
261+
with:
262+
image_name: ${{ env.CACHE_IMAGE }}
263+
image_tag: static
264+
build_extra_args: "--target static --cache-from ${{ env.CACHE_IMAGE }}:static --build-arg BUILDKIT_INLINE_CACHE=1"
265+
push_image_and_stages: false
266+
215267
- name: Cache node modules
216268
uses: actions/cache@v2
217269
env:
@@ -228,25 +280,25 @@ jobs:
228280
${{ runner.os }}-build-
229281
${{ runner.os }}-
230282
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
283+
- name: Dependency Setup
284+
run: npm install -D babel
239285

240286
- name: Static Tests
241287
run: bin/static_tests
242288

243289
static-pipeline:
244290
runs-on: ubuntu-latest
245-
container: fmrcampos/docker-ci-cache:static
246291
steps:
247292
- name: Check out repository
248293
uses: actions/checkout@v2
249294

295+
- uses: whoan/docker-build-with-cache-action@master
296+
with:
297+
image_name: ${{ env.CACHE_IMAGE }}
298+
image_tag: static
299+
build_extra_args: "--target static --cache-from ${{ env.CACHE_IMAGE }}:static --build-arg BUILDKIT_INLINE_CACHE=1"
300+
push_image_and_stages: false
301+
250302
- name: Cache node version manager
251303
uses: actions/cache@v2
252304
env:
@@ -277,14 +329,8 @@ jobs:
277329
${{ runner.os }}-build-
278330
${{ runner.os }}-
279331
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
332+
- name: Dependency Setup
333+
run: npm install -D babel
288334

289335
- name: Static Pipeline Check
290336
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)