Skip to content

Commit

Permalink
docker: build an image with compiled toolchain
Browse files Browse the repository at this point in the history
* Build an image with compiled toolchain:
  `ghcr.io/nilfoundation/proof-market-toolchain:latest`.
  It has everything to start working with the toolchain right away.
  Releases are made from a secured machine, not CI.
  However, the image is built on each commit to check that it stays
  buildable.

* Use a base build image with dependencies, including Boost 1.76.0.
  Using the base image speeds up builds a lot.

* Update readme. Encourage users to take the `:latest` image rather
  than build it themselves when they just need to use the toolchain.

* Renew build instructions: now git operations, dependencies, and build
  instructions for two different modes are grouped together.
  • Loading branch information
NickVolynkin committed Jun 16, 2023
1 parent 992025d commit 0d02356
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 109 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.git
.idea
./.*
build
Dockerfile*
scripts/.secret
scripts/.user
venv
5 changes: 5 additions & 0 deletions .github/filters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
# used by dorny/paths-filter@v2
dockerfile-base:
- 'Dockerfile.base'
- 'requirements.txt'
38 changes: 24 additions & 14 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,41 @@ concurrency:
format('{0}/{1}', github.workflow, github.ref) }}
cancel-in-progress: true

env:
IMAGE_NAME: ghcr.io/nilfoundation/proof-market-toolchain

jobs:
hadolint:
runs-on: [ ubuntu-22.04 ]
runs-on: [ self-hosted, aws_autoscaling ]
steps:
- uses: actions/checkout@v3

- uses: hadolint/[email protected]
with:
recursive: true

build:
runs-on: [ ubuntu-22.04 ]
build-image:
runs-on: [ self-hosted, aws_autoscaling ]

steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Build a Docker image
run: |
set -xe
docker build -t proof-market-toolchain .
- name: Build proof market in a container
run: |
set -xe
docker run -t \
-v $(pwd):/proof-market-toolchain \
proof-market-toolchain sh ./build.sh
- uses: dorny/paths-filter@v2
id: changes
with:
filters: .github/filters.yml

# If the base image didn't change, use one from registry
- name: Pull ${{ env.IMAGE_NAME }}:base
if: steps.changes.outputs.dockerfile-base == 'false'
run: docker pull ${{ env.IMAGE_NAME }}:base || true

# If the base image has changed, build it from scratch
- name: Rebuild ${{ env.IMAGE_NAME }}:base
if: steps.changes.outputs.dockerfile-base == 'true'
run: docker build -t ${{ env.IMAGE_NAME }}:base --file Dockerfile.base .

- name: Rebuild ${{ env.IMAGE_NAME }}:latest
run: docker build -t ${{ env.IMAGE_NAME }}:latest .
52 changes: 13 additions & 39 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,44 +1,18 @@
# syntax=docker/dockerfile:1

FROM ubuntu:22.04
RUN DEBIAN_FRONTEND=noninteractive \
set -xe \
&& apt-get update \
&& apt-get -y --no-install-recommends --no-install-suggests install \
autoconf \
automake \
build-essential \
clang-12 \
cmake \
git \
gnutls-dev \
libc-ares-dev \
libfmt-dev \
libhwloc-dev \
liblz4-dev \
libprotobuf-dev \
libsctp-dev \
libssl-dev \
libyaml-cpp-dev \
pkg-config \
ragel \
systemtap-sdt-dev \
wget \
xfslibs-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
FROM ghcr.io/nilfoundation/proof-market-toolchain:base

WORKDIR /tmp
RUN set -xe \
&& wget -q --no-check-certificate \
https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.gz \
&& tar -xvf boost_1_76_0.tar.gz \
&& rm boost_1_76_0.tar.gz
WORKDIR /proof-market-toolchain

WORKDIR /tmp/boost_1_76_0
RUN set -xe \
&& sh ./bootstrap.sh \
&& ./b2 \
&& ./b2 install
COPY . /proof-market-toolchain

WORKDIR /proof-market-toolchain
# The empty config files prevent errors from
# https://github.com/NilFoundation/proof-market-toolchain/issues/61
# To be removed after it's fixed.

RUN ./build.sh \
&& mkdir /proof-market-toolchain/.config \
&& touch /proof-market-toolchain/.config/config.ini \
&& mkdir /root/.config \
&& touch /root/.config/config.ini \
&& ln -s /proof-market-toolchain/build/bin/proof-generator/proof-generator /usr/bin/proof-generator
77 changes: 77 additions & 0 deletions Dockerfile.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# syntax=docker/dockerfile:1
# build to ghcr.io/nilfoundation/proof-market-toolchain:base

ARG BOOST_VERSION=1.76.0
ARG BOOST_VERSION_UNDERSCORED=1_76_0
ARG BOOST_SETUP_DIR=/opt/boost_${BOOST_VERSION_UNDERSCORED}
ARG BOOST_BUILD_DIRECTORY=/tmp/boost_${BOOST_VERSION_UNDERSCORED}

FROM ubuntu:22.04 as boost_builder
RUN DEBIAN_FRONTEND=noninteractive \
set -xe \
&& apt-get update \
&& apt-get -y --no-install-recommends --no-install-suggests install \
autoconf \
automake \
build-essential \
wget \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# using global args with their default versions
ARG BOOST_VERSION
ARG BOOST_VERSION_UNDERSCORED
ARG BOOST_SETUP_DIR
ARG BOOST_BUILD_DIRECTORY

WORKDIR /tmp
RUN set -xe \
&& wget -q --no-check-certificate \
https://boostorg.jfrog.io/artifactory/main/release/${BOOST_VERSION}/source/boost_${BOOST_VERSION_UNDERSCORED}.tar.gz \
&& mkdir ${BOOST_BUILD_DIRECTORY} \
&& tar -xvf boost_${BOOST_VERSION_UNDERSCORED}.tar.gz \
&& rm boost_${BOOST_VERSION_UNDERSCORED}.tar.gz

WORKDIR ${BOOST_BUILD_DIRECTORY}
RUN set -xe \
&& sh ./bootstrap.sh --prefix=${BOOST_SETUP_DIR} \
&& ./b2 --prefix=${BOOST_SETUP_DIR} \
&& ./b2 install --prefix=${BOOST_SETUP_DIR}


FROM ubuntu:22.04
LABEL Name=build-base Version=1.76.0
# using global args with their default versions
ARG BOOST_SETUP_DIR

COPY --from=boost_builder ${BOOST_SETUP_DIR} ${BOOST_SETUP_DIR}
ENV BOOST_ROOT=${BOOST_SETUP_DIR}

RUN DEBIAN_FRONTEND=noninteractive \
set -xe \
&& apt-get update \
&& apt-get -y --no-install-recommends --no-install-suggests install \
autoconf \
automake \
build-essential \
clang-12 \
cmake \
git \
gnutls-dev \
libc-ares-dev \
libfmt-dev \
libhwloc-dev \
liblz4-dev \
libprotobuf-dev \
libsctp-dev \
libssl-dev \
libyaml-cpp-dev \
pkg-config \
ragel \
systemtap-sdt-dev \
wget \
xfslibs-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /proof-market-toolchain
Loading

0 comments on commit 0d02356

Please sign in to comment.