From 4befdc302cef3ccd7304c58a59dec9ed4c8cae30 Mon Sep 17 00:00:00 2001 From: Austin Morton Date: Fri, 30 Jul 2021 15:11:41 -0400 Subject: [PATCH] Add ruby build script --- .github/workflows/build.yml | 26 +++++++++++ Dockerfile | 35 +++++++++++++++ build/build.sh | 89 +++++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 Dockerfile create mode 100755 build/build.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..8a21dda --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,26 @@ +name: Build +on: + push: + branches: [ main ] + workflow_dispatch: +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Docker Setup Buildx + uses: docker/setup-buildx-action@v1 + - name: Docker Login + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + - name: Build and push to Docker Hub + id: hub_build + uses: docker/build-push-action@v2 + with: + push: true + tags: compilerexplorer/ruby-builder:latest + cache-from: type=registry,ref=compilerexplorer/ruby-builder:latest + cache-to: type=inline + - name: Docker Hub Image Digest + run: echo ${{ steps.hub_build.outputs.digest }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cd8ae59 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,35 @@ +FROM ubuntu:18.04 +MAINTAINER Matt Godbolt + +ARG DEBIAN_FRONTEND=noninteractive +RUN apt update -y -q && apt upgrade -y -q && apt update -y -q && \ + apt -q install -y \ + autoconf \ + bison \ + build-essential \ + curl \ + git \ + libffi-dev \ + libgdbm-dev \ + libncurses5-dev \ + libreadline6-dev \ + libssl-dev \ + libyaml-dev \ + ruby \ + unzip \ + xz-utils \ + zlib1g-dev \ + && \ + cd /tmp && \ + curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \ + unzip awscliv2.zip && \ + ./aws/install && \ + rm -rf aws* \ + && \ + # Remove apt's lists to make the image smaller. + rm -rf /var/lib/apt/lists/* + +RUN mkdir -p /root +COPY build /root/ + +WORKDIR /root diff --git a/build/build.sh b/build/build.sh new file mode 100755 index 0000000..3b46630 --- /dev/null +++ b/build/build.sh @@ -0,0 +1,89 @@ +#!/bin/bash + +set -ex + +ROOT=$PWD +VERSION=$1 + +URL=https://github.com/ruby/ruby.git + +case $VERSION in +trunk) + VERSION=trunk-$(date +%Y%m%d) + BRANCH=master + ;; +*) + TAG=v${VERSION//./_} + ;; +esac + +# use tag name as branch if otherwise unspecified +BRANCH=${BRANCH-$TAG} + +# some builds checkout a tag instead of a branch +# these builds have a different prefix for ls-remote +REF=refs/heads/${BRANCH} +if [[ ! -z "${TAG}" ]]; then + REF=refs/tags/${TAG} +fi + +# determine build revision +REVISION=$(git ls-remote "${URL}" "${REF}" | cut -f 1) +LAST_REVISION="${3}" + +echo "ce-build-revision:${REVISION}" + +if [[ "${REVISION}" == "${LAST_REVISION}" ]]; then + echo "ce-build-status:SKIPPED" + exit +fi + +FULLNAME=ruby-${VERSION} +OUTPUT=${ROOT}/${FULLNAME}.tar.xz +S3OUTPUT= +if [[ $2 =~ ^s3:// ]]; then + S3OUTPUT=$2 +else + if [[ -d "${2}" ]]; then + OUTPUT=$2/${FULLNAME}.tar.xz + else + OUTPUT=${2-$OUTPUT} + fi +fi + +BUILD_DIR=${ROOT}/build +STAGING_DIR=/opt/compiler-explorer/${FULLNAME} +rm -rf "${STAGING_DIR}" +mkdir -p "${STAGING_DIR}" +mkdir -p "${BUILD_DIR}" + +# Setup ruby checkout +git clone --depth 1 --single-branch -b "${BRANCH}" "${URL}" "${ROOT}/ruby" + +# Generate autoconf +cd "${ROOT}/ruby" +if [[ -f "./autogen.sh" ]]; then + ./autogen.sh +else + # older ruby doesn't have autogen.sh + autoreconf --install +fi + +# Configure build +cd "${BUILD_DIR}" +../ruby/configure \ + --prefix="${STAGING_DIR}" \ + --disable-install-doc + +# Build and install artifacts +make -j $(nproc) +make install + +# Don't try to compress the binaries as they don't like it + +export XZ_DEFAULTS="-T 0" +tar Jcf ${OUTPUT} --transform "s,^./,./${FULLNAME}/," -C ${STAGING_DIR} . + +if [[ ! -z "${S3OUTPUT}" ]]; then + aws s3 cp --storage-class REDUCED_REDUNDANCY "${OUTPUT}" "${S3OUTPUT}" +fi