Skip to content

Commit

Permalink
fix(build): error in alpine container image builds
Browse files Browse the repository at this point in the history
Also making the build more efficient.
  • Loading branch information
edvald authored and eysi09 committed Jan 23, 2020
1 parent f7fc5f5 commit d87ea71
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 33 deletions.
86 changes: 80 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,20 @@ commands:
chmod +x kubectl
echo 'export PATH=$HOME/bin:$PATH' >> $BASH_ENV
configure_kubectl_context:
description: Configure the kubectl context so that we can access our remote cluster. Used for e2e testing.
install_gcloud:
description: Install the gcloud SDK
steps:
- install_kubectl
- run:
name: Install gcloud
command: |
mkdir $HOME/gcloud
curl https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz | tar xz -C $HOME/gcloud
$HOME/gcloud/google-cloud-sdk/install.sh --quiet
echo 'export PATH=$HOME/gcloud/google-cloud-sdk/bin:$PATH' >> $BASH_ENV
configure_kubectl_context:
description: Configure the kubectl context via gcloud so that we can access our remote cluster. Used for e2e testing.
steps:
- run:
name: Configure kubectl context via gcloud and authenticate to Google Container Registry
command: |
Expand Down Expand Up @@ -215,6 +218,8 @@ jobs:
- checkout
- run: sudo apt-get update && sudo apt-get install rsync
- npm_install
- install_kubectl
- install_gcloud
- configure_kubectl_context
- *attach-workspace
- run:
Expand All @@ -239,6 +244,8 @@ jobs:
- checkout
- run: sudo apt-get update && sudo apt-get install rsync
- npm_install
- install_kubectl
- install_gcloud
- configure_kubectl_context
- *attach-workspace
- run:
Expand Down Expand Up @@ -270,12 +277,63 @@ jobs:
- setup_remote_docker:
docker_layer_caching: true
- checkout
# This is to copy the pre-build build output from test-service (this should be a different step)
- *attach-workspace
- run:
name: Build docker images
name: Build image and push to registry
command: |
docker login -u $DOCKER_USER -p $DOCKER_PASS
TAG=gardendev/garden:${CIRCLE_SHA1}
cd garden-service
docker build -t ${TAG} -f Dockerfile .
docker push ${TAG}
build-docker-gcloud:
<<: *node-config
steps:
- setup_remote_docker:
docker_layer_caching: true
- checkout
- *attach-workspace
- run:
name: Build image and push to registry
command: |
docker login -u $DOCKER_USER -p $DOCKER_PASS
TAG=gardendev/garden-gcloud:${CIRCLE_SHA1}
cd garden-service
docker build -t ${TAG} --build-arg TAG=${CIRCLE_SHA1} -f gcloud.Dockerfile .
docker push ${TAG}
build-docker-buster:
<<: *node-config
steps:
- setup_remote_docker:
docker_layer_caching: true
- checkout
- *attach-workspace
- run:
name: Build image and push to registry
command: |
./garden-service/bin/build-containers.sh
docker login -u $DOCKER_USER -p $DOCKER_PASS
TAG=gardendev/garden:${CIRCLE_SHA1}-buster
cd garden-service
docker build -t ${TAG} -f buster.Dockerfile dist/linux-amd64
test-docker-gcloud:
docker:
- image: gardendev/garden-gcloud:${CIRCLE_SHA1}
environment:
GARDEN_DISABLE_VERSION_CHECK: "true"
GARDEN_TASK_CONCURRENCY_LIMIT: "10"
steps:
# Need to checkout to run example project
- checkout
- configure_kubectl_context
- *attach-workspace
- run:
name: Deploy demo-project with container
# overriding CIRCLE_BUILD_NUM to avoid conflict with other tests
command: CIRCLE_BUILD_NUM=$CIRCLE_BUILD_NUM-docker /garden/garden build --root examples/demo-project --env remote --logger-type basic
- run:
name: Cleanup
command: CIRCLE_BUILD_NUM=$CIRCLE_BUILD_NUM-docker kubectl delete --wait=false $(kubectl get ns -o name | grep testing-$CIRCLE_BUILD_NUM) || true
when: always
release-service-docker:
<<: *node-config
steps:
Expand Down Expand Up @@ -344,6 +402,8 @@ jobs:
steps:
# Need to checkout to run example project
- checkout
- install_kubectl
- install_gcloud
- configure_kubectl_context
- *attach-workspace
- run: sudo apt-get update && sudo apt-get -y install rsync
Expand Down Expand Up @@ -486,7 +546,21 @@ workflows:
- lint:
requires: [build]
- build-docker:
<<: *only-internal-prs
context: docker
requires: [build]
- build-docker-gcloud:
<<: *only-internal-prs
context: docker
requires: [build-docker]
- build-docker-buster:
<<: *only-internal-prs
context: docker
requires: [build-dist]
- test-docker-gcloud:
<<: *only-internal-prs
context: docker
requires: [build-docker-gcloud]
- test-service:
requires: [build]
- test-dist:
Expand Down
60 changes: 39 additions & 21 deletions garden-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
FROM node:12.13.1-alpine
ARG NODE_VERSION=12.13.1-alpine
FROM node:${NODE_VERSION} as builder

RUN apk add --no-cache \
ca-certificates \
git \
gzip \
libstdc++ \
openssl \
tar

WORKDIR /tmp

RUN npm install [email protected] && node_modules/.bin/pkg-fetch node12 alpine x64

ADD package.json /tmp/
ADD package-lock.json /tmp/

RUN npm install \
&& rm -rf /root/.npm/* \
/usr/lib/node_modules/npm/man/* \
/usr/lib/node_modules/npm/doc/* \
/usr/lib/node_modules/npm/html/* \
/usr/lib/node_modules/npm/scripts/*

ADD bin /tmp/bin
ADD build /tmp/build

RUN node_modules/.bin/pkg --target node12-alpine-x64 . \
&& mkdir -p /garden \
&& mv garden-service /garden/garden \
&& cp node_modules/sqlite3/lib/binding/node-v72-linux-x64/node_sqlite3.node /garden

#### Main container ####
FROM node:${NODE_VERSION}

# system dependencies
RUN apk add --no-cache \
bash \
curl \
Expand All @@ -13,30 +46,15 @@ RUN apk add --no-cache \
gzip \
libstdc++

VOLUME ["~/.pkg-cache"]

ADD bin /tmp/bin
ADD build /tmp/build
ADD package.json /tmp/

# build binary (need to do this in-container for alpine due to a bug in zeit/pkg)
RUN cd /tmp \
&& npm install \
&& node_modules/.bin/pkg --target node12-alpine-x64 . \
&& mkdir -p /garden \
&& mv garden-service /garden/garden \
&& rm -rf node_modules \
/root/.npm/* \
/usr/lib/node_modules/npm/man/* \
/usr/lib/node_modules/npm/doc/* \
/usr/lib/node_modules/npm/html/* \
/usr/lib/node_modules/npm/scripts/*
COPY --from=builder /garden /garden

ADD static /garden/static
RUN cd /garden/static && git init

WORKDIR /project

RUN ln -s /garden/garden /bin/garden \
RUN chmod +x /garden/garden \
&& ln -s /garden/garden /bin/garden \
&& chmod +x /bin/garden

ENTRYPOINT ["/garden/garden"]
12 changes: 6 additions & 6 deletions garden-service/bin/build-containers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ buster_tag=gardendev/garden:${version}-buster
echo "Building version ${version}"

echo "-> Build ${base_tag}"
docker build -t gardendev/garden:${version} -f Dockerfile .
docker build -t ${base_tag} -f Dockerfile .
echo "-> Check ${base_tag}"
docker run --rm -it gardendev/garden:${version} version
docker run --rm -it ${base_tag} version

echo "-> Build ${gcloud_tag}"
docker build -t gardendev/garden-gcloud:${version} --build-arg TAG=${version} -f gcloud.Dockerfile .
docker build -t ${gcloud_tag} --build-arg TAG=${version} -f gcloud.Dockerfile .
echo "-> Check ${gcloud_tag}"
docker run --rm -it gardendev/garden-gcloud:${version} version
docker run --rm -it ${gcloud_tag} version

echo "-> Build ${buster_tag}"
docker build -t gardendev/garden:${version}-buster -f buster.Dockerfile dist/linux-amd64
docker build -t ${buster_tag} -f buster.Dockerfile dist/linux-amd64
echo "-> Check ${buster_tag}"
docker run --rm -it gardendev/garden:${version}-buster version
docker run --rm -it ${buster_tag} version

1 change: 1 addition & 0 deletions garden-service/bin/push-containers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ echo "Pushing images"

docker push gardendev/garden:${version}
docker push gardendev/garden-gcloud:${version}
docker push gardendev/garden:${version}-buster

0 comments on commit d87ea71

Please sign in to comment.