Browse Source

workflow: build image from base and deps image

master 1.5.2
OhYee 8 months ago
parent
commit
0f87a3f103
  1. 42
      Dockerfile
  2. 37
      Dockerfile.base
  3. 17
      Dockerfile.deps
  4. 55
      build.bash
  5. 1
      go.mod
  6. 3
      go.sum

42
Dockerfile

@ -1,6 +1,9 @@ @@ -1,6 +1,9 @@
# syntax=docker/dockerfile:experimental
FROM golang:1.17.0 AS builder
ARG BASE_IMAGE=""
ARG DEPS_IMAGE=""
FROM ${DEPS_IMAGE} AS builder
WORKDIR /data/blotter
@ -16,42 +19,7 @@ RUN --mount=type=cache,target=/go/pkg/mod \ @@ -16,42 +19,7 @@ RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go generate
# FROM golang:1.16.3 AS prod
FROM ubuntu AS prod
RUN apt update && \
apt install -y --no-install-recommends \
ca-certificates \
graphviz \
python3 \
plantuml \
python3-pip && \
python3 -m pip install matplotlib && \
rm -rf /var/lib/apt/lists/*
# Headless chrome from https://hub.docker.com/r/justinribeiro/chrome-headless/dockerfile/
RUN apt update && \
apt install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg \
--no-install-recommends \
&& curl -sSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb https://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list \
&& apt-get update && apt-get install -y \
google-chrome-stable \
fontconfig \
fonts-ipafont-gothic \
fonts-wqy-zenhei \
fonts-thai-tlwg \
fonts-kacst \
fonts-symbola \
fonts-noto \
fonts-freefont-ttf \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*
FROM ${BASE_IMAGE} AS prod
WORKDIR /data/blotter

37
Dockerfile.base

@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
# syntax=docker/dockerfile:experimental
FROM ubuntu
RUN apt update && \
apt install -y --no-install-recommends \
ca-certificates \
graphviz \
python3 \
plantuml \
python3-pip && \
python3 -m pip install matplotlib && \
rm -rf /var/lib/apt/lists/*
# Headless chrome from https://hub.docker.com/r/justinribeiro/chrome-headless/dockerfile/
RUN apt update && \
apt install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg \
--no-install-recommends \
&& curl -sSL https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb https://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list \
&& apt-get update && apt-get install -y \
google-chrome-stable \
fontconfig \
fonts-ipafont-gothic \
fonts-wqy-zenhei \
fonts-thai-tlwg \
fonts-kacst \
fonts-symbola \
fonts-noto \
fonts-freefont-ttf \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

17
Dockerfile.deps

@ -0,0 +1,17 @@ @@ -0,0 +1,17 @@
# syntax=docker/dockerfile:experimental
FROM golang:1.17.3
WORKDIR /data/blotter
# deps cache
COPY ./go.mod ./go.sum /data/blotter/
RUN go mod download -x
RUN go build all
# build code
# build with cache: https://github.com/golang/go/issues/27719
COPY ./ /data/blotter
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go generate

55
build.bash

@ -1,11 +1,54 @@ @@ -1,11 +1,54 @@
#!/bin/bash
TAG=$(git describe --abbrev=0 --tags 2>/dev/null || git rev-parse --short HEAD)
DEPS_VERSION="0"
BASE_VERSION="0"
PROD_VERSION=$(git describe --abbrev=0 --tags 2>/dev/null || git rev-parse --short HEAD)
if [[ $1 == 'test' ]]; then
TAG="test"
BUILD_DEPS=""
BUILD_BASE=""
BUILD_PROD="1"
for arg in "$@"; do
case "$arg" in
"test") PROD_VERSION="test" ;;
"deps") BUILD_DEPS="1" BUILD_BASE="" BUILD_PROD="" ;;
"base") BUILD_DEPS="" BUILD_BASE="1" BUILD_PROD="" ;;
esac
done
DEPS_IMAGE="ohyee/blotter:deps_${DEPS_VERSION}"
BASE_IMAGE="ohyee/blotter:base_${BASE_VERSION}"
PROD_IMAGE="ohyee/blotter:${PROD_VERSION}"
echo -e "DEPS VERSION: $DEPS_IMAGE \t\t `if [[ -n \"$BUILD_DEPS\" ]]; then echo '√'; fi`"
echo -e "BASE VERSION: $BASE_IMAGE \t\t `if [[ -n \"$BUILD_BASE\" ]]; then echo '√'; fi`"
echo -e "PROD VERSION: $PROD_IMAGE \t\t `if [[ -n \"$BUILD_PROD\" ]]; then echo '√'; fi`"
echo ""
function build_docker() {
echo "Building docker image $IMAGE from $DOCKER_FILE"
docker build \
--build-arg DEPS_IMAGE=$DEPS_IMAGE \
--build-arg BASE_IMAGE=$BASE_IMAGE \
--build-arg PROD_IMAGE=$PROD_IMAGE \
-t $IMAGE \
`if [[ -n $DOCKER_FILE ]]; then echo -n "-f $DOCKER_FILE"; fi` \
.
}
if [[ -n $BUILD_PROD ]]; then
IMAGE=$PROD_IMAGE
build_docker
fi
if [[ -n $BUILD_BASE ]]; then
IMAGE=$BASE_IMAGE
DOCKER_FILE="Dockerfile.base"
build_docker
fi
IMAGE="ohyee/blotter:${TAG}"
echo $IMAGE
docker build -t ${IMAGE} .
if [[ -n $BUILD_DEPS ]]; then
IMAGE=$DEPS_IMAGE
DOCKER_FILE="Dockerfile.deps"
build_docker
fi

1
go.mod

@ -39,6 +39,7 @@ require ( @@ -39,6 +39,7 @@ require (
golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c // indirect
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 // indirect
golang.org/x/sys v0.0.0-20211109065445-02f5c0300f6e // indirect
golang.org/x/text v0.3.4 // indirect
google.golang.org/genproto v0.0.0-20201203001206-6486ece9c497 // indirect
google.golang.org/grpc v1.34.0 // indirect

3
go.sum

@ -319,8 +319,9 @@ golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7w @@ -319,8 +319,9 @@ golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201207223542-d4d67f95c62d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210525143221-35b2ab0089ea h1:+WiDlPBBaO+h9vPNZi8uJ3k4BkKQB7Iow3aqwHVA5hI=
golang.org/x/sys v0.0.0-20210525143221-35b2ab0089ea/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211109065445-02f5c0300f6e h1:i6Vklmyu+fZMFYpum+sR4ZWABGW7MyIxfJZXYvcnbns=
golang.org/x/sys v0.0.0-20211109065445-02f5c0300f6e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=

Loading…
Cancel
Save