Skip to content

Commit

Permalink
actions/ctr: build erlang/otp and rebar3 ourselves
Browse files Browse the repository at this point in the history
  • Loading branch information
Sando authored and sando38 committed Oct 21, 2023
1 parent 392de79 commit 9137610
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 5 deletions.
86 changes: 83 additions & 3 deletions .github/workflows/container-build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,61 @@ jobs:
if-no-files-found: error
retention-days: 5

################################################################################
#' build Erlang/OTP and rebar3 for directly compilation.
build-erlang-rebar:
name: Build Erlang/OTP and Rebar3
runs-on: ubuntu-latest
needs: [detect-change]
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
-
name: Check out repository code
uses: actions/checkout@v3
with:
fetch-depth: 0
-
name: On push master | extract git version and define build mode
if: needs.detect-change.outputs.update == 'false'
run: |
echo "OTP_VSN=$(awk '/^otp_vsn=/ {{gsub(/[^0-9.]/, ""); print}}' tools/make-binaries)" >> $GITHUB_ENV
echo "REBAR_VSN=$(awk '/^rebar_vsn=/ {{gsub(/[^0-9.]/, ""); print}}' tools/make-binaries)" >> $GITHUB_ENV
-
name: On release | extract git version and define build mode
if: needs.detect-change.outputs.update == 'true'
run: |
echo "OTP_VSN=$(wget -O - https://raw.githubusercontent.com/${{ github.repository }}/$eturnal_vsn/tools/make-binaries \
| awk '/^otp_vsn=/ {{gsub(/[^0-9.]/, ""); print}}')" >> $GITHUB_ENV
echo "REBAR_VSN=$(wget -O - https://raw.githubusercontent.com/${{ github.repository }}/$eturnal_vsn/tools/make-binaries \
| awk '/^rebar_vsn=/ {{gsub(/[^0-9.]/, ""); print}}')" >> $GITHUB_ENV
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
-
name: Build Erlang/OTP ${{ env.OTP_VSN }} base image
uses: docker/build-push-action@v4
with:
build-args: |
OTP_VSN=${{ env.OTP_VSN }}
REBAR_VSN=${{ env.REBAR_VSN }}
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
file: tools/Dockerfile.erlang
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/386,linux/arm/v7,linux/ppc64le
push: true
tags: localhost:5000/erlang:otp-${{ env.OTP_VSN }}

################################################################################
#' build container images with local source files
build-ctr:
Expand All @@ -286,7 +341,12 @@ jobs:
arch: [386, arm/v7, ppc64le]
method: [build]
fail-fast: false
needs: [detect-change]
needs: [detect-change, build-erlang-rebar]
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
-
name: Check out repository code
Expand All @@ -301,6 +361,7 @@ jobs:
echo "TAG_VERSION=$(echo "$(./tools/get-version)" | sed -e 's|+|-|')" >> $GITHUB_ENV
echo "SRC=local" >> $GITHUB_ENV
echo "OTP_VSN=$(awk '/^otp_vsn=/ {{gsub(/[^0-9.]/, ""); print}}' tools/make-binaries)" >> $GITHUB_ENV
echo "REBAR_VSN=$(awk '/^rebar_vsn=/ {{gsub(/[^0-9.]/, ""); print}}' tools/make-binaries)" >> $GITHUB_ENV
-
name: On release | extract git version and define build mode
if: needs.detect-change.outputs.update == 'true'
Expand All @@ -312,6 +373,8 @@ jobs:
# define erlang/OTP version
echo "OTP_VSN=$(wget -O - https://raw.githubusercontent.com/${{ github.repository }}/$eturnal_vsn/tools/make-binaries \
| awk '/^otp_vsn=/ {{gsub(/[^0-9.]/, ""); print}}')" >> $GITHUB_ENV
echo "REBAR_VSN=$(wget -O - https://raw.githubusercontent.com/${{ github.repository }}/$eturnal_vsn/tools/make-binaries \
| awk '/^rebar_vsn=/ {{gsub(/[^0-9.]/, ""); print}}')" >> $GITHUB_ENV
# check whether to build from archive or git, because git repo is HEAD here
# hence, we would not build the specifc release when updating the ctr image
Expand All @@ -326,6 +389,23 @@ jobs:
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
-
name: Build Erlang/OTP ${{ env.OTP_VSN }} base image
uses: docker/build-push-action@v4
with:
build-args: |
OTP_VSN=${{ env.OTP_VSN }}
REBAR_VSN=${{ env.REBAR_VSN }}
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
file: tools/Dockerfile.erlang
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/386,linux/arm/v7,linux/ppc64le
push: true
tags: localhost:5000/erlang:otp-${{ env.OTP_VSN }}
-
name: Extract build & environment variables
run: |
Expand Down Expand Up @@ -357,7 +437,7 @@ jobs:
build-args: |
SOURCE=${{ env.SRC }}
VERSION=${{ env.VSN }}
OTP_VSN=${{ env.OTP_VSN }}
BUILD_IMAGE=localhost:5000/erlang:otp-${{ env.OTP_VSN }}
REPOSITORY=https://github.com/${{ github.repository }}.git
REBAR_CT=${{ env.REBAR_CT }}
VARIANT=standalone
Expand Down Expand Up @@ -401,7 +481,7 @@ jobs:
build-args: |
SOURCE=${{ env.SRC }}
VERSION=${{ env.VSN }}
OTP_VSN=${{ env.OTP_VSN }}
BUILD_IMAGE=localhost:5000/erlang:otp-${{ env.OTP_VSN }}
REPOSITORY=https://github.com/${{ github.repository }}.git
REBAR_CT=${{ env.REBAR_CT }}
VARIANT=acme
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#' Define default build variables
## specific ARGs for METHOD='build'
ARG OTP_VSN='25.3.0.0'
ARG OTP_VSN='26.1.1'
ARG BUILD_IMAGE="docker.io/erlang:${OTP_VSN}-alpine"
## specific ARGs for METHOD='package'
ARG ALPINE_VSN='3.18'
ARG ALPINE_VSN='3.18.4'
ARG PACKAGE_IMAGE="docker.io/alpine:${ALPINE_VSN}"
## specific ARGs for VARIANT='acme'
ARG ACMESH_VSN='3.0.6'
Expand Down
71 changes: 71 additions & 0 deletions tools/Dockerfile.erlang
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
ARG OTP_VSN="26.1.1"
ARG REBAR_VSN="3.22.1"
ARG ALPINE_VSN="3.18"

FROM alpine:${ALPINE_VSN}
ARG OTP_VSN
ARG REBAR_VSN
ARG ARCH

ENV OTP_VERSION="${OTP_VSN}" \
REBAR3_VERSION="${REBAR_VSN}"

LABEL org.opencontainers.image.version=$OTP_VERSION

RUN set -xe \
&& OTP_DOWNLOAD_URL="https://github.com/erlang/otp/archive/OTP-${OTP_VERSION}.tar.gz" \
&& apk add --no-cache --virtual .fetch-deps \
curl \
ca-certificates \
&& curl -fSL -o otp-src.tar.gz "$OTP_DOWNLOAD_URL" \
&& apk add --no-cache --virtual .build-deps \
dpkg-dev dpkg \
gcc \
g++ \
libc-dev \
linux-headers \
make \
autoconf \
ncurses-dev \
openssl-dev \
unixodbc-dev \
lksctp-tools-dev \
tar \
&& export ERL_TOP="/usr/src/otp_src_${OTP_VERSION%%@*}" \
&& mkdir -vp $ERL_TOP \
&& tar -xzf otp-src.tar.gz -C $ERL_TOP --strip-components=1 \
&& rm otp-src.tar.gz \
&& ( cd $ERL_TOP \
&& ./otp_build autoconf \
&& gnuArch="$(dpkg-architecture --query DEB_HOST_GNU_TYPE)" \
&& ./configure --build="$gnuArch" \
&& make -j$(getconf _NPROCESSORS_ONLN) \
&& make install ) \
&& rm -rf $ERL_TOP \
&& find /usr/local -regex '/usr/local/lib/erlang/\(lib/\|erts-\).*/\(man\|doc\|obj\|c_src\|emacs\|info\|examples\)' | xargs rm -rf \
&& find /usr/local -name src | xargs -r find | grep -v '\.hrl$' | xargs rm -v || true \
&& find /usr/local -name src | xargs -r find | xargs rmdir -vp || true \
&& scanelf --nobanner -E ET_EXEC -BF '%F' --recursive /usr/local | xargs -r strip --strip-all \
&& scanelf --nobanner -E ET_DYN -BF '%F' --recursive /usr/local | xargs -r strip --strip-unneeded \
&& runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)" \
&& REBAR3_DOWNLOAD_URL="https://github.com/erlang/rebar3/archive/${REBAR3_VERSION}.tar.gz" \
&& curl -fSL -o rebar3-src.tar.gz "$REBAR3_DOWNLOAD_URL" \
&& mkdir -p /usr/src/rebar3-src \
&& tar -xzf rebar3-src.tar.gz -C /usr/src/rebar3-src --strip-components=1 \
&& rm rebar3-src.tar.gz \
&& cd /usr/src/rebar3-src \
&& HOME=$PWD ./bootstrap \
&& install -v ./rebar3 /usr/local/bin/ \
&& rm -rf /usr/src/rebar3-src \
&& apk add --virtual .erlang-rundeps \
$runDeps \
lksctp-tools \
ca-certificates \
&& apk del .fetch-deps .build-deps

CMD ["erl"]

0 comments on commit 9137610

Please sign in to comment.