Improve container build process

This commit is contained in:
asonix 2020-01-28 15:08:16 -06:00
parent 35ba1dbd96
commit cb5bb45912
5 changed files with 30 additions and 111 deletions

View file

@ -1,18 +1,18 @@
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
ifeq ($(TAG),)
TAG = $(shell git rev-parse --abbrev-ref HEAD)-$(shell git rev-parse HEAD)
endif
DOCKERFILE = "container/Dockerfile"
DOCKERFILE_DEPS = "container/Dockerfile-deps"
IMAGE_NAME = "asonix/mastodon"
DEPS_IMAGE_NAME = "asonix/masto-deps"
masto: images push-images
masto: images
all: deps push-deps images push-images
all: deps images
deps:
./container/build-images.sh container/Dockerfile-deps $(DEPS_IMAGE_NAME)
push-deps:
./container/push-containers.sh $(DEPS_IMAGE_NAME)
./container/build-images.sh $(DOCKERFILE_DEPS) $(TAG) $(DEPS_IMAGE_NAME)
images:
./container/build-images.sh container/Dockerfile "$(GIT_BRANCH)"
push-images:
./container/push-containers.sh $(GIT_BRANCH)
./container/build-images.sh $(DOCKERFILE) $(TAG) $(IMAGE_NAME)

View file

@ -1,4 +1,4 @@
FROM asonix/masto-deps:amd64 as build-dep
FROM asonix/masto-deps:latest-amd64 as build-dep
# Use bash for the shell
SHELL ["bash", "-c"]
@ -6,7 +6,8 @@ SHELL ["bash", "-c"]
COPY Gemfile* package.json yarn.lock /opt/mastodon/
RUN cd /opt/mastodon && \
bundle install -j$(nproc) --deployment --without development test && \
bundle config set deployment 'true' \
bundle install -j$(nproc) --without development test && \
yarn install --pure-lockfile
FROM amd64/ubuntu:18.04

View file

@ -1,70 +0,0 @@
FROM arm64v8/ubuntu:18.04
# Install Node
ENV NODE_VER="12.11.1"
ENV ARCH="arm64"
RUN echo "Etc/UTC" > /etc/localtime && \
apt update && \
apt -y install wget python && \
cd ~ && \
wget https://nodejs.org/download/release/v$NODE_VER/node-v$NODE_VER-linux-$ARCH.tar.gz && \
tar xf node-v$NODE_VER-linux-$ARCH.tar.gz && \
rm node-v$NODE_VER-linux-$ARCH.tar.gz && \
mv node-v$NODE_VER-linux-$ARCH /opt/node
# Install jemalloc
ENV JE_VER="5.2.1"
RUN apt update && \
apt -y install make autoconf gcc g++ && \
cd ~ && \
wget https://github.com/jemalloc/jemalloc/archive/$JE_VER.tar.gz && \
tar xf $JE_VER.tar.gz && \
cd jemalloc-$JE_VER && \
./autogen.sh && \
./configure --prefix=/opt/jemalloc && \
make -j$(nproc) > /dev/null && \
make install_bin install_include install_lib
# Install ruby
ENV RUBY_VER="2.6.5"
ENV CPPFLAGS="-I/opt/jemalloc/include"
ENV LDFLAGS="-L/opt/jemalloc/lib/"
RUN apt update && \
apt -y install build-essential \
bison libyaml-dev libgdbm-dev libreadline-dev \
libncurses5-dev libffi-dev zlib1g-dev libssl-dev && \
cd ~ && \
wget https://cache.ruby-lang.org/pub/ruby/${RUBY_VER%.*}/ruby-$RUBY_VER.tar.gz && \
tar xf ruby-$RUBY_VER.tar.gz && \
cd ruby-$RUBY_VER && \
./configure --prefix=/opt/ruby \
--with-jemalloc \
--with-shared \
--disable-install-doc && \
ln -s /opt/jemalloc/lib/* /usr/lib/ && \
make -j$(nproc) > /dev/null && \
make install
ENV PATH="${PATH}:/opt/ruby/bin:/opt/node/bin"
RUN npm install -g yarn && \
gem install bundler && \
apt update && \
apt -y install git libicu-dev libidn11-dev \
libpq-dev libprotobuf-dev protobuf-compiler
# Add tini
ENV TINI_VERSION="0.18.0"
ENV TINI_ARCH="arm64"
ADD https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-${TINI_ARCH} /tini
ADD https://github.com/krallin/tini/releases/download/v${TINI_VERSION}/tini-${TINI_ARCH}.asc /tini.asc
RUN apt update && \
apt -y --no-install-recommends install gpg gpg-agent dirmngr
RUN gpg --batch \
--keyserver hkp://p80.pool.sks-keyservers.net:80 \
--recv-keys 595E85A6B1B4779EA4DAAEC70B588DFF0527A9B7 && \
gpg --batch --verify /tini.asc /tini
RUN chmod +rx /tini

View file

@ -3,7 +3,8 @@
set -xe
SOURCE=$1
TAG=$2
TAG=$(echo $2 | sed 's/\//-/g')
NAME=$3
require_input() {
input=$1
@ -16,9 +17,10 @@ require_input() {
}
require_input "$SOURCE" "Dockerfile"
require_input "$TAG" "container tag"
require_input "$TAG" "image tag"
require_input "$NAME" "image name"
ARCHITECTURES=('arm64v8' 'amd64')
ARCHITECTURES=('arm64v8')
for architecture in "${ARCHITECTURES[@]}"; do
cp "$SOURCE" "$SOURCE-$architecture"
@ -30,13 +32,22 @@ for architecture in "${ARCHITECTURES[@]}"; do
fi
if [ "$architecture" == arm64v8 ]; then
sed -i'' 's/:amd64/:arm64v8/g' "$SOURCE-$architecture" # source image
sed -i'' 's/:latest-amd64/:latest-arm64v8/g' "$SOURCE-$architecture" # source image
sed -i'' 's/FROM amd64/FROM arm64v8/g' "$SOURCE-$architecture" # source image
sed -i'' 's/x64/arm64/g' "$SOURCE-$architecture" # for node
sed -i'' 's/amd64/arm64/g' "$SOURCE-$architecture" # for tini
fi
docker build --pull --no-cache -f "$SOURCE-$architecture" -t "$TAG:$architecture" .
docker build \
--pull \
--no-cache \
-f "$SOURCE-$architecture" \
-t "$NAME:$TAG-$architecture" \
-t "$NAME:latest-$architecture" \
.
docker push "$NAME:$TAG-$architecture"
docker push "$NAME:latest-$architecture"
rm "$SOURCE-$architecture"
done

View file

@ -1,23 +0,0 @@
#!/usr/bin/env bash
set -xe
TAG=$1
require_input() {
input=$1
name=$2
if [ "$input" == "" ]; then
echo "Input, $name, required but not present"
exit 1;
fi
}
require_input "$TAG" "container tag"
ARCHITECTURES=('arm64v8' 'amd64')
for arch in "${ARCHITECTURES[@]}"; do
docker push "$TAG:$arch"
done