Add CI for ARM architectures (#2127)

This commit is contained in:
Laurence Isla
2022-06-03 22:19:16 -05:00
committed by Steve Chavez
parent d16972e8da
commit 74678391c6
4 changed files with 292 additions and 3 deletions
+57
View File
@@ -0,0 +1,57 @@
#!/bin/bash
# This script builds PostgREST in a remote ARM server. It uses Docker to
# build for multiple platforms (aarch64 and armv7 on ubuntu).
# The Dockerfile is located in ./docker-env
[ -z "$1" ] && { echo "Missing 1st argument: PostgREST github commit SHA"; exit 1; }
[ -z "$2" ] && { echo "Missing 2nd argument: Docker repo"; exit 1; }
[ -z "$3" ] && { echo "Missing 3rd argument: Docker username"; exit 1; }
[ -z "$4" ] && { echo "Missing 4th argument: Docker password"; exit 1; }
[ -z "$5" ] && { echo "Missing 5th argument: Build environment directory name"; exit 1; }
PGRST_GITHUB_COMMIT="$1"
DOCKER_REPO="$2"
DOCKER_USER="$3"
DOCKER_PASS="$4"
SCRIPT_PATH="$5"
DOCKER_BUILD_PATH="$SCRIPT_PATH/docker-env"
clean_env()
{
sudo docker logout
}
# Login to Docker
sudo docker logout
{ echo $DOCKER_PASS | sudo docker login -u $DOCKER_USER --password-stdin; } || { echo "Couldn't login to docker"; exit 1; }
trap clean_env sigint sigterm exit
# Move to the docker build environment
cd ~/$DOCKER_BUILD_PATH
# Build ARM versions
sudo docker buildx build --build-arg PGRST_GITHUB_COMMIT=$PGRST_GITHUB_COMMIT \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--platform linux/arm/v7,linux/arm64 \
--cache-from $DOCKER_REPO/postgrest-build-arm \
--target=postgrest-build \
-t $DOCKER_REPO/postgrest-build-arm \
--push .
sudo docker logout
# Generate and copy binaries to the local filesystem
sudo docker buildx build --build-arg PGRST_GITHUB_COMMIT=$PGRST_GITHUB_COMMIT \
--cache-from $DOCKER_REPO/postgrest-build-arm \
--platform linux/arm/v7,linux/arm64 \
--target=postgrest-bin \
-o result .
# Compress binaries
sudo chown -R ubuntu:ubuntu ~/$DOCKER_BUILD_PATH/result
mv ~/$DOCKER_BUILD_PATH/result ~/$SCRIPT_PATH/result
cd ~/$SCRIPT_PATH
tar -cJf result.tar.xz result
+73
View File
@@ -0,0 +1,73 @@
# Build PostgREST for ARM architectures
FROM ubuntu:focal as postgrest-build
RUN apt-get update -y \
&& apt-get upgrade -y \
&& apt-get install -y git build-essential curl libffi-dev libffi7 libgmp-dev libgmp10 libncurses-dev libncurses5 libtinfo5 llvm libnuma-dev zlib1g-dev libpq-dev jq gcc \
&& apt-get clean
# Install ghcup
ENV BOOTSTRAP_HASKELL_NONINTERACTIVE=1
RUN bash -c "curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh"
# Add ghcup to PATH
ENV PATH=${PATH}:/root/.local/bin
ENV PATH=${PATH}:/root/.ghcup/bin
# Install cabal
RUN bash -c "ghcup upgrade"
RUN bash -c "ghcup install cabal 3.4.0.0"
RUN bash -c "ghcup set cabal 3.4.0.0"
# Install GHC
RUN bash -c "ghcup install ghc 8.10.7"
RUN bash -c "ghcup set ghc 8.10.7"
# Update Path to include Cabal and GHC exports
RUN bash -c "echo PATH="$HOME/.local/bin:$PATH" >> $HOME/.bashrc"
RUN bash -c "echo export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH" >> $HOME/.bashrc"
RUN bash -c "source $HOME/.bashrc"
# Clone the repository
RUN git clone https://github.com/PostgREST/postgrest.git /postgrest
WORKDIR /postgrest
RUN cabal v2-update && cabal v2-build
# Arguments are declared here to save the above installation in cache
ARG PGRST_GITHUB_COMMIT
RUN git pull origin main \
&& git checkout $PGRST_GITHUB_COMMIT
# Build PostgREST
RUN mkdir -p /build-export
RUN cabal v2-update && cabal v2-build
RUN PGRST_BIN=$(cabal exec which postgrest | tail -1) \
&& mv $PGRST_BIN /build-export
# Simple image to generate the PostgREST binaries
FROM scratch as postgrest-bin
COPY --from=postgrest-build /build-export /
# PostgREST docker hub image
FROM ubuntu:focal AS postgrest
RUN apt-get update -y
RUN apt install libpq-dev zlib1g-dev jq gcc libnuma-dev -y
RUN apt-get clean
COPY --from=postgrest-bin postgrest /usr/bin/postgrest
EXPOSE 3000
USER 1000
CMD postgrest
+52
View File
@@ -0,0 +1,52 @@
#!/bin/bash
# This script publishes the Docker ARM images to Docker Hub.
[ -z "$1" ] && { echo "Missing 1st argument: PostgREST github commit SHA"; exit 1; }
[ -z "$2" ] && { echo "Missing 2nd argument: Docker repo"; exit 1; }
[ -z "$3" ] && { echo "Missing 3rd argument: Docker username"; exit 1; }
[ -z "$4" ] && { echo "Missing 4th argument: Docker password"; exit 1; }
[ -z "$5" ] && { echo "Missing 5th argument: Build environment directory name"; exit 1; }
[ -z "$6" ] && { echo "Missing 6th argument: PostgREST version"; exit 1; }
PGRST_GITHUB_COMMIT="$1"
DOCKER_REPO="$2"
DOCKER_USER="$3"
DOCKER_PASS="$4"
SCRIPT_PATH="$5"
PGRST_VERSION="v$6"
IS_PRERELEASE="$7"
DOCKER_BUILD_PATH="$SCRIPT_PATH/docker-env"
clean_env()
{
sudo docker logout
}
# Login to Docker
sudo docker logout
{ echo $DOCKER_PASS | sudo docker login -u $DOCKER_USER --password-stdin; } || { echo "Couldn't login to docker"; exit 1; }
trap clean_env sigint sigterm exit
# Move to the docker build environment
cd ~/$DOCKER_BUILD_PATH
# Push final images to Docker hub
# NOTE: This command publishes a separate ARM image because the builds cannot
# be added to the manifest if they are not in the registry beforehand.
# This image must be manually deleted from Docker Hub at the end of the process.
sudo docker buildx build --build-arg PGRST_GITHUB_COMMIT=$PGRST_GITHUB_COMMIT \
--platform linux/arm/v7,linux/arm64 \
--cache-from $DOCKER_REPO/postgrest-build-arm \
-t $DOCKER_REPO/postgrest:$PGRST_VERSION-arm \
--push .
# Add the arm images to the manifest
# NOTE: This assumes that there already is a `postgrest:<version>` image
# for the amd64 architecture pushed to Docker Hub
sudo docker buildx imagetools create --append -t $DOCKER_REPO/postgrest:$PGRST_VERSION $DOCKER_REPO/postgrest:$PGRST_VERSION-arm
[ -z $IS_PRERELEASE ] && sudo docker buildx imagetools create --append -t $DOCKER_REPO/postgrest:latest $DOCKER_REPO/postgrest:$PGRST_VERSION-arm
sudo docker logout