feat: build the magefile into a binary

This commit builds the magefile into a binary during the docker build
stage.
The Dockerfile is updated to include a multi-stage build where the first
stage compiles the binary and the second stage builds the final
cv-builder image.
The final image is now based on debian:buster instead of
golang:<VERSION>-buster which significantly reduces the image's size.
This commit is contained in:
Dan Anglin 2020-09-13 22:50:17 +01:00
parent 964fea7938
commit 84b29f0467
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
3 changed files with 31 additions and 7 deletions

View file

@ -1 +1,5 @@
*
!magefile.go
!helpers/*
!go.mod
!go.sum

View file

@ -21,9 +21,9 @@
.docker-test-rules:
rules:
- if: '$CI_COMMIT_BRANCH'
changes:
- changes:
- "docker/Dockerfile"
- "*.go"
when: always
- if: '$CI_COMMIT_REF_NAME =~ /^[0-9]{4}(.[0-9]{2}){2}$/'
when: never
@ -39,9 +39,7 @@
.docker-publish-rules:
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PROJECT_PATH == "dananglin/cv"'
changes:
- "docker/Dockerfile"
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PROJECT_PATH == "dananglin/cv" && $CI_PIPELINE_SOURCE == "web" && $BUILD_DOCKER_IMAGE == "true"'
when: always
#------------------------------------------------#

View file

@ -1,11 +1,33 @@
FROM golang:1.14.6-buster
FROM golang:1.15.2-buster AS builder
# Upgrade packages and install dependencies
RUN git clone https://github.com/magefile/mage "${GOPATH}/src/mage"
WORKDIR ${GOPATH}/src/mage
RUN go run bootstrap.go
COPY go.mod ${GOPATH}/cv-builder/
COPY go.sum ${GOPATH}/cv-builder/
COPY magefile.go ${GOPATH}/cv-builder/
COPY helpers ${GOPATH}/cv-builder/helpers
WORKDIR ${GOPATH}/cv-builder
RUN mage -compile /usr/local/bin/cv-make
FROM debian:buster
COPY --from=builder /usr/local/bin/cv-make /usr/local/bin
# Install dependencies
RUN \
apt-get update && \
apt-get install -y --no-install-recommends \
fonts-crosextra-carlito=20130920-1 \
rsync=3.1.3-6 \
curl=7.64.0-4+deb10u1 \
aspell=0.60.7~20110707-6 \
aspell-en=2018.04.16-0-1 \
&& \
apt-get clean autoclean && \
apt-get autoremove -y && \