Skip to content

Commit

Permalink
test using buildx during circleci builds (#1200)
Browse files Browse the repository at this point in the history
* test using buildx during circleci builds

* fix buildx context create syntax

* add actual buildx context create

* try enabling buildkit

* don't overwrite setup_remote_docker

* use export buildkit

* manually install buildx

* set plain progress, load docker image on build
  • Loading branch information
mipyykko committed May 29, 2023
1 parent 45334c9 commit 3e1095b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
24 changes: 23 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,22 @@ jobs:
steps:
- checkout
- setup_remote_docker:
version: "20.10.18"
docker_layer_caching: true
- restore_cache:
keys:
- dependency-cache-{{ checksum "frontend/package.json" }}-checksum "frontend/package-lock.json" }}
- dependency-cache-{{ checksum "frontend/package.json" }}
- run:
name: Install Docker Buildx
command: |
mkdir -vp ~/.docker/cli-plugins/
curl --silent -L "https://github.com/docker/buildx/releases/download/v0.10.5/buildx-v0.10.5.linux-amd64" > ~/.docker/cli-plugins/docker-buildx
chmod a+x ~/.docker/cli-plugins/docker-buildx
docker buildx version
export DOCKER_BUILDKIT=1
docker buildx create --name buildx-frontend --use
docker buildx install
- run:
name: "Build frontend image"
command: "bin/build-docker-frontend.sh"
Expand Down Expand Up @@ -190,9 +201,10 @@ jobs:
steps:
- checkout
- setup_remote_docker:
version: "20.10.18"
docker_layer_caching: true
- jq/install
- docker/install-docker-tools
# - docker/install-docker-tools
- run:
name: patch-package hash
command: md5sum backend/patches/* > backend/patches.hash
Expand All @@ -201,6 +213,16 @@ jobs:
- dependency-cache-{{ checksum "backend/package-lock.json" }}-{{ checksum "backend/prisma/schema.prisma" }}-{{ checksum "backend/patches.hash" }}
- dependency-cache-{{ checksum "backend/package-lock.json" }}-{{ checksum "backend/prisma/schema.prisma" }}
- dependency-cache-{{ checksum "backend/package-lock.json" }}
- run:
name: Install Docker Buildx
command: |
mkdir -vp ~/.docker/cli-plugins/
curl --silent -L "https://github.com/docker/buildx/releases/download/v0.10.5/buildx-v0.10.5.linux-amd64" > ~/.docker/cli-plugins/docker-buildx
chmod a+x ~/.docker/cli-plugins/docker-buildx
docker buildx version
export DOCKER_BUILDKIT=1
docker buildx create --name buildx-backend --use
docker buildx install
- run:
name: "Build backend image"
command: "bin/build-docker-backend.sh"
Expand Down
5 changes: 3 additions & 2 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM node:18.16.0-alpine

RUN apk update && \
apk --no-cache add \
apk add \
build-base \
libpng-dev \
postgresql-client \
Expand All @@ -18,9 +18,10 @@ RUN wget https://github.com/edenhill/librdkafka/archive/v2.1.1.tar.gz -O - | ta
&& make && make install \
&& cd ..
# when node image incorporates alpine 3.18
# RUN apk --no-cache add \
# RUN apk add \
# librdkafka=2.1.1-r0 \
# librdkafka-dev=2.1.1-r0
RUN rm -rf /var/cache/apk/*

RUN mkdir -p /app && chown -R node /app

Expand Down
2 changes: 1 addition & 1 deletion bin/build-docker-backend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ docker pull eu.gcr.io/moocfi/moocfi-backend:latest || true

echo Building "$TAG"

docker build . --cache-from eu.gcr.io/moocfi/moocfi-backend:latest -f Dockerfile -t "$TAG" --build-arg=GIT_COMMIT="$(git rev-parse --short HEAD)"
docker build . --cache-from eu.gcr.io/moocfi/moocfi-backend:latest -f Dockerfile -t "$TAG" --load --progress=plain --build-arg=GIT_COMMIT="$(git rev-parse --short HEAD)"

echo "Successfully built image: $TAG"

Expand Down
2 changes: 1 addition & 1 deletion bin/build-docker-frontend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ docker pull eu.gcr.io/moocfi/moocfi-frontend:latest || true

echo Building "$TAG"

docker build . --cache-from eu.gcr.io/moocfi/moocfi-frontend:latest -f Dockerfile -t "$TAG"
docker build . --cache-from eu.gcr.io/moocfi/moocfi-frontend:latest -f Dockerfile -t "$TAG" --load --progress=plain

echo "Copying node_modules and next cache from container to host"
docker create -ti --name frontend_tmp "$TAG" sh
Expand Down

0 comments on commit 3e1095b

Please sign in to comment.