Skip to content

Commit 7593b2d

Browse files
authored
Use registry + local cache instead of gha (#24658)
1 parent 0358910 commit 7593b2d

File tree

3 files changed

+99
-8
lines changed

3 files changed

+99
-8
lines changed

.dockerignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.git/
2+
node_modules/
3+
.github/
4+
.vscode/
5+
docs/
6+
script/
+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Build and Push Main Docker Cache
2+
3+
# **What it does**: Builds and pushes the `main` Docker cache image
4+
# **Why we have it**: It allows PRs using the registry cache to pull a pre-built image, which should speed up the build
5+
# **Who does it impact**: All contributors.
6+
7+
on:
8+
push:
9+
branches:
10+
- main
11+
12+
permissions:
13+
contents: read
14+
15+
# This allows a subsequently queued workflow run to take priority over
16+
# previously queued runs and interrupt currently executing runs
17+
concurrency:
18+
group: '${{ github.workflow }}'
19+
cancel-in-progress: true
20+
21+
jobs:
22+
build-and-push-nonprod-cache:
23+
runs-on: ubuntu-latest
24+
timeout-minutes: 15
25+
env:
26+
NONPROD_REGISTRY_USERNAME: ghdocs
27+
NONPROD_REGISTRY_NAME: ghdocs
28+
DOCKER_IMAGE_MAIN_REF: ${{ secrets.NONPROD_REGISTRY_SERVER }}/${{ github.repository }}:main
29+
30+
steps:
31+
- name: 'Az CLI login'
32+
uses: azure/login@66d2e78565ab7af265d2b627085bc34c73ce6abb
33+
with:
34+
creds: ${{ secrets.NONPROD_AZURE_CREDENTIALS }}
35+
36+
- name: 'Docker login'
37+
uses: azure/docker-login@81744f9799e7eaa418697cb168452a2882ae844a
38+
with:
39+
login-server: ${{ secrets.NONPROD_REGISTRY_SERVER }}
40+
username: ${{ env.NONPROD_REGISTRY_USERNAME }}
41+
password: ${{ secrets.NONPROD_REGISTRY_PASSWORD }}
42+
43+
- name: Set up Docker Buildx
44+
uses: docker/setup-buildx-action@94ab11c41e45d028884a99163086648e898eed25
45+
46+
- name: Check out repo
47+
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
48+
with:
49+
# To prevent issues with cloning early access content later
50+
persist-credentials: 'false'
51+
lfs: 'true'
52+
53+
- name: Check out LFS objects
54+
run: git lfs checkout
55+
56+
- if: ${{ github.repository == 'github/docs-internal' }}
57+
name: Clone early access
58+
env:
59+
DOCUBOT_REPO_PAT: ${{ secrets.DOCUBOT_REPO_PAT }}
60+
GIT_BRANCH: main
61+
run: npm install dotenv && node script/early-access/clone-for-build.js
62+
63+
- name: 'Build and push image'
64+
uses: docker/build-push-action@a66e35b9cbcf4ad0ea91ffcaf7bbad63ad9e0229
65+
with:
66+
context: .
67+
push: true
68+
target: ${{ fromJSON('["production", "production_early_access"]')[github.repository == 'github/docs-internal'] }}
69+
tags: ${{ env.DOCKER_IMAGE_MAIN_REF }}
70+
cache-from: type=registry,ref=${{ env.DOCKER_IMAGE_MAIN_REF }}
71+
cache-to: type=registry,mode=max,ref=${{ env.DOCKER_IMAGE_MAIN_REF }}

.github/workflows/staging-build-and-deploy-azure.yml

+22-8
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ jobs:
6767
- name: Set up Docker Buildx
6868
uses: docker/setup-buildx-action@94ab11c41e45d028884a99163086648e898eed25
6969

70+
- name: Cache Docker layers
71+
uses: actions/cache@937d24475381cd9c75ae6db12cb4e79714b926ed
72+
with:
73+
path: /tmp/.buildx-cache
74+
key: ${{ runner.os }}-buildx-${{ github.sha }}
75+
restore-keys: |
76+
${{ runner.os }}-buildx-
77+
7078
- name: Check out repo
7179
uses: actions/checkout@1e204e9a9253d643386038d443f96446fa156a97
7280
with:
@@ -78,12 +86,6 @@ jobs:
7886
- name: Check out LFS objects
7987
run: git lfs checkout
8088

81-
- name: Setup node
82-
uses: actions/setup-node@04c56d2f954f1e4c69436aa54cfef261a018f458
83-
with:
84-
node-version: 16.13.x
85-
cache: npm
86-
8789
- if: ${{ github.repository == 'github/docs-internal' }}
8890
name: Clone early access
8991
env:
@@ -98,8 +100,12 @@ jobs:
98100
push: true
99101
target: ${{ fromJSON('["production", "production_early_access"]')[github.repository == 'github/docs-internal'] }}
100102
tags: ${{ env.DOCKER_IMAGE }}
101-
cache-from: type=gha
102-
cache-to: type=gha,mode=max
103+
# we only pull the `main` cache image
104+
cache-from: |
105+
type=local,src=/tmp/.buildx-cache
106+
type=registry,ref=${{ secrets.NONPROD_REGISTRY_SERVER }}/${{ github.repository }}:main
107+
# `main-docker-cache.yml` handles updating the remote cache so we don't pollute it with PR specific code
108+
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
103109

104110
# Succeed despite any non-zero exit code (e.g. if there is no deployment to cancel)
105111
- name: 'Cancel any existing deployments for this PR'
@@ -124,3 +130,11 @@ jobs:
124130
dockerRegistryPassword="${{ secrets.NONPROD_REGISTRY_PASSWORD }}"
125131

126132
- run: echo ${{ steps.deploy.outputs.defaultHostName }}
133+
134+
- # Fixes cache growth problem
135+
# https://github.com/docker/build-push-action/issues/252
136+
# https://github.com/moby/buildkit/issues/1896
137+
name: Move cache
138+
run: |
139+
rm -rf /tmp/.buildx-cache
140+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

0 commit comments

Comments
 (0)