diff --git a/.github/workflows/make-build-image.yml b/.github/workflows/make-build-image.yml new file mode 100644 index 00000000000..4066ea1462b --- /dev/null +++ b/.github/workflows/make-build-image.yml @@ -0,0 +1,62 @@ +--- +name: Make a build image + +on: + push: + branches: ["ow-build-image*"] + +jobs: + calc_ver: + # calculate versions from git tags + runs-on: ubuntu-latest + outputs: + project_ver: ${{steps.vers.outputs.project_ver}} + build_ver: ${{steps.vers.outputs.build_ver}} + full_ver: ${{steps.vers.outputs.full_ver}} + release_flag: ${{steps.vers.outputs.release_flag}} + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Calculate versions + id: vers + shell: bash + run: ${{github.workspace}}/build-scripts/for-github/calc-version-from-git.bash + + build-image: + needs: [calc_ver] + + strategy: + matrix: + include: + - run_on: ubuntu-latest + for: linux + prepare: debian-based + base_image: ubuntu:18.04 + image_name: foundationdb-build + + env: + IMAGE_NAME: ${{ matrix.image_name }}:${{ needs.calc_ver.outputs.full_ver }} + + runs-on: ${{ matrix.run_on }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Build an image + run: | + podman build \ + -v ${{github.workspace}}:/mnt/project:ro,Z \ + -f ${{github.workspace}}/build-scripts/for-${{ matrix.for }}/build-${{ matrix.prepare }}.Dockerfile \ + --build-arg IMAGE=${{ matrix.base_image }} \ + --build-arg PROJECT_NAME=foundationdb \ + --build-arg FOR_OS=${{ matrix.for }} \ + -t $IMAGE_NAME + + - name: Log in to registry + # This is where you will update the personal access token to GITHUB_TOKEN + run: echo "${{ secrets.GITHUB_TOKEN }}" | podman login ghcr.io -u $ --password-stdin + + - name: Push image + run: podman push $IMAGE_NAME ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME diff --git a/build-scripts/for-github/calc-version-from-git.bash b/build-scripts/for-github/calc-version-from-git.bash new file mode 100755 index 00000000000..4d2f525be9a --- /dev/null +++ b/build-scripts/for-github/calc-version-from-git.bash @@ -0,0 +1,24 @@ +#!/bin/bash + +# Calculate version numbers from git tags and set them to github output +# Assume that current directory is a github repository + +# Do not set github variables when running outside github +[[ -z "$GITHUB_OUTPUT" ]] && GITHUB_OUTPUT=/dev/null + +git fetch --prune --unshallow --tags --force +GIT_VERSION=`git describe --tags` +PROJECT_VERSION=`echo $GIT_VERSION | cut -d- -f1` +BUILD_VERSION=`echo $GIT_VERSION | cut -d- -f2-3 --output-delimiter=.` +GIT_CHANGE_NUM=`echo $GIT_VERSION | cut -d- -f3` +if [[ -n "$GIT_CHANGE_NUM" ]] || [[ "$BUILD_VERSION" < "1" ]]; then + RELEASE_FLAG=OFF +else + RELEASE_FLAG=ON +fi + +# Display versions and set Github environment +echo "project_ver=$PROJECT_VERSION" | tee -a $GITHUB_OUTPUT +echo "build_ver=$BUILD_VERSION" | tee -a $GITHUB_OUTPUT +echo "full_ver=$PROJECT_VERSION-$BUILD_VERSION" | tee -a $GITHUB_OUTPUT +echo "release_flag=$RELEASE_FLAG" | tee -a $GITHUB_OUTPUT diff --git a/build-scripts/for-linux/build-debian-based.Dockerfile b/build-scripts/for-linux/build-debian-based.Dockerfile new file mode 100644 index 00000000000..13802814694 --- /dev/null +++ b/build-scripts/for-linux/build-debian-based.Dockerfile @@ -0,0 +1,23 @@ +# Any debian-based image is suitable +ARG IMAGE=ubuntu:18.04 +FROM ${IMAGE} + +ARG PROJECT_NAME +ARG FOR_OS=linux + +# The prroject directory must be mounted to /mnt/project + +# Set up the runner user +RUN \ + apt update \ + && apt install -y sudo apt-utils \ + && useradd -mN runner \ + && echo "runner ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/90-runner + +USER runner +WORKDIR /home/runner + +# Install dependencies +RUN /mnt/project/build-scripts/for-${FOR_OS}/prepare-debian-based.bash + +LABEL org.opencontainers.image.description="An image for building ${PROJECT_NAME} for ${FOR_OS} from sources"