Skip to content

Commit

Permalink
chore: Improve image build speed #1919 (#1948)
Browse files Browse the repository at this point in the history
* chore: Improve image build speed #2

Signed-off-by: Justin Marquis <[email protected]>

* chore: Added test-arm-image test for arm64

Signed-off-by: Justin Marquis <[email protected]>

* chore: enabled buildkit for docker build commands

Signed-off-by: Justin Marquis <[email protected]>

* chore: support for releases and further docker optimizations

Signed-off-by: Justin Marquis <[email protected]>
  • Loading branch information
34fathombelow authored Apr 11, 2022
1 parent 633892d commit a8ae46a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 40 deletions.
23 changes: 6 additions & 17 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@ jobs:

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

# - name: Cache Docker layers
# uses: actions/cache@v2
# with:
# path: /tmp/.buildx-cache
# key: ${{ runner.os }}-buildx-${{ github.sha }}
# restore-keys: |
# ${{ runner.os }}-buildx-
with:
config-inline: |
[worker.oci]
gc = false
- name: Docker meta (controller)
id: controller-meta
Expand Down Expand Up @@ -76,7 +72,8 @@ jobs:
id: platform-matrix
run: |
PLATFORM_MATRIX=linux/amd64
if [ ${{ github.event_name != 'pull_request' }} = true ]; then
if [[ "${{ github.event_name }}" == "push" || "${{ contains(github.event.pull_request.labels.*.name, 'test-arm-image') }}" == "true" ]]
then
PLATFORM_MATRIX=$PLATFORM_MATRIX,linux/arm64
fi
echo "::set-output name=platform-matrix::$PLATFORM_MATRIX"
Expand All @@ -95,11 +92,3 @@ jobs:
platforms: ${{ steps.platform-matrix.outputs.platform-matrix }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.plugin-meta.outputs.tags }}

# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
# - name: Move cache
# run: |
# rm -rf /tmp/.buildx-cache
# mv /tmp/.buildx-cache-new /tmp/.buildx-cache
19 changes: 3 additions & 16 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ jobs:

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ steps.get-sha.outputs.sha }}
config-inline: |
[worker.oci]
gc = false
- name: Print Disk Usage
run: |
Expand Down Expand Up @@ -84,8 +82,6 @@ jobs:
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.controller-meta.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Build and push (plugin-image)
uses: docker/build-push-action@v2
Expand All @@ -95,16 +91,7 @@ jobs:
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.plugin-meta.outputs.tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new

# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

release-artifacts:
runs-on: ubuntu-latest
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ RUN touch ui/dist/node_modules.marker && \
touch ui/dist/app/index.html && \
find ui/dist

ARG TARGETOS TARGETARCH
ARG MAKE_TARGET="controller plugin plugin-linux plugin-darwin plugin-windows"
ARG TARGETOS
ARG TARGETARCH
ARG MAKE_TARGET="controller plugin"
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make ${MAKE_TARGET}

####################################################################################################
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,22 @@ docs:

.PHONY: builder-image
builder-image:
docker build -t $(IMAGE_PREFIX)argo-rollouts-ci-builder:$(IMAGE_TAG) --target builder .
DOCKER_BUILDKIT=1 docker build -t $(IMAGE_PREFIX)argo-rollouts-ci-builder:$(IMAGE_TAG) --target builder .
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)argo-rollouts:$(IMAGE_TAG) ; fi

.PHONY: image
image:
ifeq ($(DEV_IMAGE), true)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -v -i -ldflags '${LDFLAGS}' -o ${DIST_DIR}/rollouts-controller-linux-amd64 ./cmd/rollouts-controller
docker build -t $(IMAGE_PREFIX)argo-rollouts:$(IMAGE_TAG) -f Dockerfile.dev ${DIST_DIR}
DOCKER_BUILDKIT=1 docker build -t $(IMAGE_PREFIX)argo-rollouts:$(IMAGE_TAG) -f Dockerfile.dev ${DIST_DIR}
else
docker build -t $(IMAGE_PREFIX)argo-rollouts:$(IMAGE_TAG) .
DOCKER_BUILDKIT=1 docker build -t $(IMAGE_PREFIX)argo-rollouts:$(IMAGE_TAG) .
endif
@if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)argo-rollouts:$(IMAGE_TAG) ; fi

.PHONY: plugin-image
plugin-image:
docker build --target kubectl-argo-rollouts -t $(IMAGE_PREFIX)kubectl-argo-rollouts:$(IMAGE_TAG) .
DOCKER_BUILDKIT=1 docker build --target kubectl-argo-rollouts -t $(IMAGE_PREFIX)kubectl-argo-rollouts:$(IMAGE_TAG) .
if [ "$(DOCKER_PUSH)" = "true" ] ; then docker push $(IMAGE_PREFIX)kubectl-argo-rollouts:$(IMAGE_TAG) ; fi

.PHONY: lint
Expand Down
3 changes: 2 additions & 1 deletion hack/build-release-plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ SRCROOT="$( CDPATH='' cd -- "$(dirname "$0")/.." && pwd -P )"
mkdir -p ${SRCROOT}/dist

rollout_iid_file=$(mktemp -d "${SRCROOT}/dist/rollout_iid.XXXXXXXXX")
docker build --iidfile ${rollout_iid_file} --target argo-rollouts-build .
DOCKER_BUILDKIT=1 docker build --iidfile ${rollout_iid_file} --build-arg MAKE_TARGET="plugin-linux plugin-darwin plugin-windows" \
--target argo-rollouts-build .
rollout_iid=$(cat ${rollout_iid_file})
container_id=$(docker create ${rollout_iid})

Expand Down

0 comments on commit a8ae46a

Please sign in to comment.