Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share the Go build cache when building in Dockerfiles #1853

Merged
merged 1 commit into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/integration-k8s-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Integration tests (K8s)

on:
pull_request:
branches: ['master']

concurrency:
group: int-test-k8s-${{ github.head_ref }}
cancel-in-progress: true

jobs:
tests:
env:
IMAGE_REPO: 'localhost:5000'
REGISTRY: 'localhost:5000'
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.17
- uses: actions/checkout@v2
- uses: docker/setup-buildx-action@v1

- name: Run build-image-and-k8s-integration-test
run: |
make travis-setup
make minikube-setup
make k8s-executor-build-push
make integration-test-k8s
20 changes: 8 additions & 12 deletions .github/workflows/integration-layers-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
name: Integration tests (Layers)

# Triggers the workflow on push or pull request events
on: [pull_request]
on:
pull_request:
branches: ['master']

concurrency:
group: int-test-layers-${{ github.head_ref }}
cancel-in-progress: true

jobs:
build-executor:
tests:
env:
IMAGE_REPO: 'localhost:5000'
REGISTRY: 'localhost:5000'
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
- uses: actions/setup-go@v2
with:
go-version: 1.14
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 0
go-version: 1.17
- uses: actions/checkout@v2
- uses: docker/setup-buildx-action@v1

- name: Run integration-test-layers
run: |
Expand Down
42 changes: 19 additions & 23 deletions .github/workflows/integration-misc.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
name: Integration Tests Misc

# Triggers the workflow on push or pull request events
on: [pull_request]
on:
pull_request:
branches: ['master']

concurrency:
group: int-test-mis-${{ github.head_ref }}
cancel-in-progress: true

jobs:
build-executor:
tests:
env:
IMAGE_REPO: 'localhost:5000'
REGISTRY: 'localhost:5000'
Expand All @@ -17,25 +18,20 @@ jobs:
TRAVIS_PULL_REQUEST: ${{ github.event.number }}
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.14
id: go
- uses: actions/setup-go@v2
with:
go-version: 1.17
- uses: actions/checkout@v2
- uses: docker/setup-buildx-action@v1

- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Print Travis ENV vars
run: |
echo "TRAVIS_BRANCH: ${TRAVIS_BRANCH}"
echo "TRAVIS_PULL_REQUEST: ${TRAVIS_PULL_REQUEST}"
echo "TRAVIS_REPO_SLUG: ${TRAVIS_REPO_SLUG}"

- name: Print Travis ENV vars
run: |
echo "TRAVIS_BRANCH: ${TRAVIS_BRANCH}"
echo "TRAVIS_PULL_REQUEST: ${TRAVIS_PULL_REQUEST}"
echo "TRAVIS_REPO_SLUG: ${TRAVIS_REPO_SLUG}"

- name: Run integration-test-misc
run : |
make travis-setup
make minikube-setup
make integration-test-misc
- name: Run integration-test-misc
run : |
make travis-setup
make minikube-setup
make integration-test-misc
31 changes: 14 additions & 17 deletions .github/workflows/integration-run-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
name: Integration tests (Run)

# Triggers the workflow on push or pull request events
on: [pull_request]
on:
pull_request:
branches: ['master']

concurrency:
group: int-test-run-${{ github.head_ref }}
cancel-in-progress: true

jobs:
build-executor:
tests:
env:
IMAGE_REPO: 'localhost:5000'
REGISTRY: 'localhost:5000'
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.14
id: go
- uses: actions/setup-go@v2
with:
go-version: 1.17
- uses: actions/checkout@v2
- uses: docker/setup-buildx-action@v1

- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Run integration-test-run
run: |
make travis-setup
make minikube-setup
make integration-test-run
- name: Run integration-test-run
run: |
make travis-setup
make minikube-setup
make integration-test-run
33 changes: 0 additions & 33 deletions .github/workflows/integration_k8_tests.yaml

This file was deleted.

28 changes: 9 additions & 19 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
name: Unit tests

# Triggers the workflow on push or pull request events
on: [pull_request]
on:
pull_request:
branches: ['master']

concurrency:
group: unit-tests-${{ github.head_ref }}
cancel-in-progress: true

jobs:
build-executor:
env:
IMAGE_REPO: 'localhost:5000'
REGISTRY: 'localhost:5000'
tests:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.14
id: go
- uses: actions/setup-go@v2
with:
go-version: 1.17
- uses: actions/checkout@v2

- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Run unit-test
run:
make test
- run: make test
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ integration-test-misc:

.PHONY: k8s-executor-build-push
k8s-executor-build-push:
docker build ${BUILD_ARG} --build-arg=GOARCH=$(GOARCH) -t $(REGISTRY)/executor:latest -f deploy/Dockerfile .
DOCKER_BUILDKIT=1 docker build ${BUILD_ARG} --build-arg=GOARCH=$(GOARCH) -t $(REGISTRY)/executor:latest -f deploy/Dockerfile .
docker push $(REGISTRY)/executor:latest

.PHONY: images
Expand Down
5 changes: 4 additions & 1 deletion deploy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ RUN go install github.com/chrismellard/docker-credential-acr-env@09e2b5a8ac86c3e
RUN mkdir -p /kaniko/.docker

COPY . .
RUN make GOARCH=$TARGETARCH
RUN \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
make GOARCH=$TARGETARCH

# Generate latest ca-certificates

Expand Down
7 changes: 5 additions & 2 deletions deploy/Dockerfile_debug
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ RUN go install github.com/chrismellard/docker-credential-acr-env@09e2b5a8ac86c3e
RUN mkdir -p /kaniko/.docker

COPY . .
RUN make GOARCH=$TARGETARCH
RUN make GOARCH=$TARGETARCH out/warmer
RUN \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
make GOARCH=$TARGETARCH && \
make GOARCH=$TARGETARCH out/warmer

# Generate latest ca-certificates

Expand Down
5 changes: 4 additions & 1 deletion deploy/Dockerfile_slim
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ ARG TARGETARCH
WORKDIR /src
COPY . .

RUN make GOARCH=$TARGETARCH
RUN \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
make GOARCH=$TARGETARCH

# Generate latest ca-certificates

Expand Down
5 changes: 4 additions & 1 deletion deploy/Dockerfile_warmer
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ RUN go install github.com/chrismellard/docker-credential-acr-env@09e2b5a8ac86c3e
RUN mkdir -p /kaniko/.docker

COPY . .
RUN make GOARCH=$TARGETARCH out/warmer
RUN \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
make GOARCH=$TARGETARCH out/warmer

# Generate latest ca-certificates

Expand Down
1 change: 1 addition & 0 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func buildRequiredImages() error {
for _, setupCmd := range setupCommands {
fmt.Println(setupCmd.name)
cmd := exec.Command(setupCmd.command[0], setupCmd.command[1:]...)
cmd.Env = append(os.Environ(), "DOCKER_BUILDKIT=1") // Build with buildkit enabled.
if out, err := RunCommandWithoutTest(cmd); err != nil {
return errors.Wrap(err, fmt.Sprintf("%s failed: %s", setupCmd.name, string(out)))
}
Expand Down
1 change: 0 additions & 1 deletion scripts/integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ IMAGE_REPO="${IMAGE_REPO:-gcr.io/kaniko-test}"

docker version

# Sets up a kokoro (Google internal integration testing tool) environment
echo "Running integration tests..."
make out/executor
make out/warmer
Expand Down