From c092f97fa48fb33f8ff36b84f495c29655d92fac Mon Sep 17 00:00:00 2001 From: Fritz Schaal Date: Thu, 1 Apr 2021 16:51:21 +0200 Subject: [PATCH] WIP --- Dockerfile | 53 +++++++++++++++---------------- build.sh | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 26 deletions(-) create mode 100644 build.sh diff --git a/Dockerfile b/Dockerfile index 275a038..86568b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,36 +1,37 @@ -ARG GO_VERSION=alpine +FROM archlinux as build -FROM golang:${GO_VERSION} as build - -ARG NODE_10_SRC="http://dl-cdn.alpinelinux.org/alpine/v3.10/main/x86_64" - -# NPM_APK=$(wget -qO- "${NODE_10_SRC}" | gawk 'match($0,/^.*href="(npm-10\..*\.apk)".*$/,ary) { print ary[1] }') && \ -# wget -O nodejs10.apk "${NODE_10_SRC}/${NODE_APK}" && \ -# wget -O npm10.apk "${NODE_10_SRC}/${NODE_APK}" && \ -# apk add nodejs10.apk npm10.apk - -RUN \ - apk update --no-cache && \ - apk add --no-cache gawk && \ - NODE_APK=$(wget -qO- "${NODE_10_SRC}" | gawk 'match($0,/^.*href="(nodejs-10\..*\.apk)".*$/,ary) { print ary[1] }') && \ - wget -O nodejs10.apk "${NODE_10_SRC}/${NODE_APK}" && \ - apk add nodejs10.apk - -RUN \ - apk update --no-cache &&\ - apk add --no-cache \ - bash \ +RUN pacman -Syu --noconfirm \ + base-devel \ git \ - make \ + go \ + nodejs-lts-erbium \ npm \ - yarn && \ - git config --global advice.detachedHead false + sudo \ + yarn + +RUN \ + echo -e 'root ALL=(ALL) ALL\n%wheel ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers && \ + useradd -m -U -G wheel builduser + +USER builduser + +RUN \ + cd && \ + export GOROOT=/usr/lib/go && \ + export GOPATH=${HOME}/go && \ + export PATH=${PATH}:${GOROOT}/bin:${GOPATH}/bin && \ + git config --global advice.detachedHead false && \ + git clone https://aur.archlinux.org/yay-git.git && \ + cd yay-git && \ + makepkg --syncdeps --install --noconfirm && \ + yay -S --noconfirm \ + nodejs-ember-cli ARG VAULT_VERSION= ARG VAULT_REPO ARG BUILD_PATH=vault -RUN --mount=type=tmpfs,target=/go/src/ \ +RUN --mount=type=tmpfs,target=/home/builduser/go/src/ \ echo "selected repo: ${VAULT_REPO}" && \ if [ -z "${VAULT_VERSION}" ]; then \ VAULT_VERSION=$( \ @@ -40,7 +41,7 @@ RUN --mount=type=tmpfs,target=/go/src/ \ fi && \ echo "selected vault branch: ${VAULT_VERSION}" && \ BUILD_PATH=$(echo "${VAULT_REPO}" | sed -E 's/^.*\/\/(.*)\.git/\1/') && \ - BUILD_PATH="/go/src/${BUILD_PATH}" && \ + BUILD_PATH="${GOPATH}/src/${BUILD_PATH}" && \ git clone \ --branch="${VAULT_VERSION}" \ --depth=1 \ diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..63a5eba --- /dev/null +++ b/build.sh @@ -0,0 +1,91 @@ +#!/bin/bash + +set -e + +trap cleanup ERR SIGTERM + +cleanup() { + # docker kill vault_build + echo "end" +} + +BUILDDIR='/tmp/vault_build' +OUT_DIR='/tmp/vault/' +ARCH_DOCKER_REPO='https://scm.f1x.online/mirrors/archlinux-docker.git' +VAULT_REPO='https://scm.f1x.online/mirrors/vault.git' + +mkdir -vp "${BUILDDIR}" "${OUT_DIR}" + +pushd "${BUILDDIR}" + +### fetch & docker-build build container code +test -d arch_docker_repo || git clone --depth=1 "${ARCH_DOCKER_REPO}" arch_docker_repo +cd arch_docker_repo +#git fetch && git pull +make image-base + +cat << EOF_BUILD_BASE | docker build -t bb:local - +FROM archlinux/archlinux:base +RUN pacman --noconfirm -Syu \ + base-devel \ + git \ + go \ + gox \ + make \ + nodejs-lts-erbium \ + npm \ + python2 \ + yarn +RUN mkdir -p /src/github.com/hashicorp +RUN cd /src/github.com/hashicorp && \ + git clone --depth=1 ${VAULT_REPO} +EOF_BUILD_BASE + +### run build container +test -n "$(docker ps -aq -f name=vault_build)" || \ + docker run \ + -d \ + --rm \ + --name vault_build \ + -v /etc/pacman.d/mirrorlist:/etc/pacman.d/mirrorlist:ro \ + bb:local \ + sleep infinity + +### setup build env +# docker exec vault_build \ +# pacman --noconfirm -Syu \ +# base-devel \ +# git \ +# go \ +# gox \ +# make \ +# npm \ +# python2 \ +# yarn +# docker exec vault_build \ +# mkdir -p /src/github.com/hashicorp +# docker exec -w /src/github.com/hashicorp vault_build \ +# git clone --depth=1 "${VAULT_REPO}" + +### build +docker exec \ + -e XC_OSARCH=linux/amd64 \ + -w /src/github.com/hashicorp/vault vault_build \ + make bootstrap +docker exec \ + -e GOPATH=/root/go \ + -e XC_OSARCH=linux/amd64 \ + -w /src/github.com/hashicorp/vault vault_build \ + make static-dist bin + +### copy binary +docker cp \ + vault_build:/src/github.com/hashicorp/vault/bin/vault - > "${OUT_DIR}/vault" +stat "${OUT_DIR}/vault" + +### cleanup +popd +docker kill vault_build +rm -rd "${BUILDDIR}" + +exit 0