Skip to content

Commit 6af8055

Browse files
authored
CLOUDP-150873: Cache go dependencies (#802)
cache go modules and docker layers
1 parent fde4296 commit 6af8055

File tree

8 files changed

+112
-48
lines changed

8 files changed

+112
-48
lines changed

.github/actions/build-push-image/action.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ inputs:
1010
repository:
1111
description: The name of repository to build image
1212
required: true
13+
file:
14+
description: Name of the dockerfile relative to context
15+
required: false
16+
default: Dockerfile
1317
docker_username:
1418
description: The username to access the docker registry
1519
required: true
@@ -59,13 +63,31 @@ runs:
5963
with:
6064
username: ${{ inputs.docker_username }}
6165
password: ${{ inputs.docker_password }}
66+
- name: Set up Go
67+
uses: actions/setup-go@v3
68+
with:
69+
go-version-file: "${{ github.workspace }}/go.mod"
70+
- name: Setup cache
71+
uses: actions/cache@v3
72+
with:
73+
path: |
74+
~/.cache/go-build
75+
~/go/pkg/mod
76+
key: ${{ runner.os }}-build-${{ hashFiles('**/go.sum') }}
77+
- name: Download go build dependencies
78+
shell: bash
79+
run: |
80+
go mod download
6281
- name: Build and Push Operator to Docker Registry
6382
uses: docker/build-push-action@v3
6483
with:
6584
context: .
85+
file: ${{ inputs.file }}
6686
build-args: VERSION=${{ inputs.version }}
6787
platforms: ${{ inputs.platforms }}
6888
tags: ${{ inputs.repository }}:${{ inputs.version }}
89+
cache-from: type=gha
90+
cache-to: type=gha,mode=max
6991
push: true
7092
- name: Login to quay.io registry
7193
if: ${{ inputs.push_to_quay == true }}
@@ -79,7 +101,10 @@ runs:
79101
uses: docker/build-push-action@v3
80102
with:
81103
context: .
104+
file: ${{ inputs.file }}
82105
build-args: VERSION=${{ inputs.version }}
83106
platforms: ${{ inputs.platforms }}
84107
tags: quay.io/${{ inputs.repository }}:${{ inputs.version }}
108+
cache-from: type=gha
109+
cache-to: type=gha,mode=max
85110
push: true

.github/workflows/cleanup-all.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- name: Set up Go
4343
uses: actions/setup-go@v3
4444
with:
45-
go-version: '1.19'
45+
go-version-file: "${{ github.workspace }}/go.mod"
4646

4747
- name: Run cleanup VPC
4848
if: github.event_name == 'schedule' || github.event.inputs.cleanVPC == 'true'

.github/workflows/lint.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Setup Go
2121
uses: actions/setup-go@v3
2222
with:
23-
go-version: "1.18"
23+
go-version-file: "${{ github.workspace }}/go.mod"
2424

2525
- name: golangci-lint
2626
uses: golangci/[email protected]

.github/workflows/openshift-upgrade-test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
- name: Setup Go
5555
uses: actions/setup-go@v3
5656
with:
57-
go-version: "1.18"
57+
go-version-file: "${{ github.workspace }}/go.mod"
5858

5959
- name: Download tools for openshift test
6060
run: |

.github/workflows/release-branch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Setup Go
3737
uses: actions/setup-go@v3
3838
with:
39-
go-version: "1.18"
39+
go-version-file: "${{ github.workspace }}/go.mod"
4040

4141
- name: Download dependencies
4242
run: |

.github/workflows/test-e2e.yml

Lines changed: 76 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,22 @@ jobs:
1313
name: Prepare E2E configuration and image
1414
runs-on: ubuntu-latest
1515
env:
16-
# uncomment the below for local testing
17-
# DOCKER_REPO: ${{ env.DOCKER_REGISTRY }}/mongodb-atlas-kubernetes-operator
1816
DOCKER_REPO: mongodb/mongodb-atlas-kubernetes-operator-prerelease
1917
steps:
20-
- name: Check out code
18+
- if: ${{ inputs.forked == false }}
19+
name: Check out code
2120
uses: actions/[email protected]
2221
with:
2322
submodules: true
24-
fetch-depth: 0 # required for tags
23+
fetch-depth: 0
24+
- if: ${{ inputs.forked == true }}
25+
name: Check out code
26+
uses: actions/[email protected]
27+
with:
28+
submodules: true
29+
ref: ${{github.event.pull_request.head.sha}}
30+
repository: ${{github.event.pull_request.head.repo.full_name}}
31+
fetch-depth: 0
2532
- name: Prepare tag
2633
id: prepare
2734
uses: ./.github/actions/set-tag
@@ -34,16 +41,72 @@ jobs:
3441
docker_username: ${{ secrets.DOCKER_USERNAME }}
3542
docker_password: ${{ secrets.DOCKER_PASSWORD }}
3643
push_to_quay: false
44+
forked: ${{ inputs.forked }}
45+
prepare-e2e-bundle:
46+
name: Prepare E2E Bundle configuration and image
47+
runs-on: ubuntu-latest
48+
env:
49+
DOCKER_REGISTRY: docker.io
50+
DOCKER_REPO: mongodb/mongodb-atlas-kubernetes-operator-prerelease
51+
DOCKER_BUNDLES_REPO: mongodbinternal/mongodb-atlas-kubernetes-bundles-prerelease
52+
steps:
53+
- if: ${{ inputs.forked == false }}
54+
name: Check out code
55+
uses: actions/[email protected]
56+
with:
57+
submodules: true
58+
fetch-depth: 0
59+
- if: ${{ inputs.forked == true }}
60+
name: Check out code
61+
uses: actions/[email protected]
62+
with:
63+
submodules: true
64+
ref: ${{github.event.pull_request.head.sha}}
65+
repository: ${{github.event.pull_request.head.repo.full_name}}
66+
fetch-depth: 0
67+
- name: Prepare tag
68+
id: prepare
69+
uses: ./.github/actions/set-tag
70+
- name: Generate configuration for the tests
71+
uses: ./.github/actions/gen-install-scripts
72+
with:
73+
IMAGE_URL: ${{ env.DOCKER_REPO }}:${{ steps.prepare.outputs.tag }}
74+
VERSION: ${{ steps.prepare.outputs.tag }}
75+
ENV: dev
76+
- name: Change path for the test
77+
run: |
78+
awk '{gsub(/cloud.mongodb.com/, "cloud-qa.mongodb.com", $0); print}' bundle/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml > tmp && mv tmp bundle/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml
79+
- name: Cache all files
80+
uses: actions/cache@v3
81+
with:
82+
path: ./*
83+
key: ${{ github.sha }}
84+
- name: Prepare docker tag
85+
id: prepare-docker-bundle-tag
86+
run: |
87+
REPOSITORY=${{ env.DOCKER_BUNDLES_REPO }}
88+
TAG=${{ steps.prepare.outputs.tag }}
89+
TAGS="${REPOSITORY}:${TAG}"
90+
echo "tags=$TAGS" >> $GITHUB_OUTPUT
91+
- name: Build and Push image
92+
uses: ./.github/actions/build-push-image
93+
with:
94+
file: bundle.Dockerfile
95+
repository: ${{ env.DOCKER_BUNDLES_REPO }}
96+
version: ${{ steps.prepare.outputs.tag }}
97+
platforms: linux/amd64
98+
docker_username: ${{ secrets.DOCKER_USERNAME }}
99+
docker_password: ${{ secrets.DOCKER_PASSWORD }}
100+
push_to_quay: false
101+
forked: ${{ inputs.forked }}
37102
e2e:
38103
name: E2E tests
39-
needs: prepare-e2e
104+
needs: [prepare-e2e, prepare-e2e-bundle]
40105
runs-on: ubuntu-latest
41106
env:
42-
# uncomment the below for local testing
43-
# DOCKER_REPO: ${{ env.DOCKER_REGISTRY }}/mongodb-atlas-kubernetes-operator
44107
DOCKER_REGISTRY: docker.io
45-
DOCKER_BUNDLES_REPO: mongodbinternal/mongodb-atlas-kubernetes-bundles-prerelease
46108
DOCKER_REPO: mongodb/mongodb-atlas-kubernetes-operator-prerelease
109+
DOCKER_BUNDLES_REPO: mongodbinternal/mongodb-atlas-kubernetes-bundles-prerelease
47110
strategy:
48111
fail-fast: false
49112
matrix:
@@ -74,42 +137,14 @@ jobs:
74137
"teams",
75138
]
76139
steps:
77-
- name: Check out code
78-
uses: actions/checkout@v3.1.0
140+
- name: Cache all files
141+
uses: actions/cache@v3
79142
with:
80-
submodules: recursive
143+
path: ./*
144+
key: ${{ github.sha }}
81145
- name: Prepare tag
82146
id: prepare
83147
uses: ./.github/actions/set-tag
84-
- name: Generate configuration for the tests
85-
uses: ./.github/actions/gen-install-scripts
86-
with:
87-
IMAGE_URL: ${{ env.DOCKER_REPO }}:${{ steps.prepare.outputs.tag }}
88-
VERSION: ${{ steps.prepare.outputs.tag }}
89-
ENV: dev
90-
- name: Change path for the test
91-
run: |
92-
awk '{gsub(/cloud.mongodb.com/, "cloud-qa.mongodb.com", $0); print}' bundle/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml > tmp && mv tmp bundle/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml
93-
- name: Login to docker.io
94-
uses: docker/login-action@v2
95-
with:
96-
username: ${{ secrets.DOCKER_USERNAME }}
97-
password: ${{ secrets.DOCKER_PASSWORD }}
98-
- name: Prepare docker tag
99-
id: prepare-docker-bundle-tag
100-
run: |
101-
REPOSITORY=${{ env.DOCKER_BUNDLES_REPO }}
102-
TAG=${{ steps.prepare.outputs.tag }}
103-
TAGS="${REPOSITORY}:${TAG}"
104-
echo "tags=$TAGS" >> $GITHUB_OUTPUT
105-
- name: Push bundle-image for the test
106-
if: ${{ matrix.test == 'openshift' || matrix.test == 'bundle-test' && !env.ACT }}
107-
uses: docker/build-push-action@v3
108-
with:
109-
context: .
110-
push: true
111-
tags: ${{ steps.prepare-docker-bundle-tag.outputs.tags }}
112-
file: bundle.Dockerfile
113148
- name: Set properties
114149
id: properties
115150
run: |
@@ -129,7 +164,7 @@ jobs:
129164
- name: Setup Go
130165
uses: actions/setup-go@v3
131166
with:
132-
go-version: "1.18"
167+
go-version-file: "${{ github.workspace }}/go.mod"
133168
- name: Install operator-sdk-v1.22.0
134169
run: |
135170
wget https://github.com/operator-framework/operator-sdk/releases/download/v1.22.0/operator-sdk_linux_amd64 -q

.github/workflows/test-int.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ jobs:
3838
- name: Cache multiple paths
3939
uses: actions/cache@v3
4040
with:
41-
path: ~/go/pkg/mod
41+
path: |
42+
~/.cache/go-build
43+
~/go/pkg/mod
4244
key: ${{ runner.os }}-build-${{ hashFiles('**/go.sum') }}
4345

4446
- name: Run testing

.github/workflows/test-unit.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ jobs:
2525
- name: Cache multiple paths
2626
uses: actions/cache@v3
2727
with:
28-
path: ~/go/pkg/mod
28+
path: |
29+
~/.cache/go-build
30+
~/go/pkg/mod
2931
key: ${{ runner.os }}-build-${{ hashFiles('**/go.sum') }}
3032

3133
- name: Setup Go
3234
uses: actions/setup-go@v3
3335
with:
34-
go-version: "1.18"
36+
go-version-file: "${{ github.workspace }}/go.mod"
3537

3638
- run: go version
3739

0 commit comments

Comments
 (0)