From 3f1ec30d0b09ae5a4f5d111c343f015ea062706f Mon Sep 17 00:00:00 2001 From: jupblb Date: Mon, 8 Sep 2025 15:40:39 +0200 Subject: [PATCH 1/2] Add standalone scip-ruby Docker image for CI/CD - Split Docker configuration into three files: - Dockerfile.base: Common dependencies and scip-ruby binary - Dockerfile: Standard scip-ruby image for CI/CD pipelines - Dockerfile.autoindex: Autoindex variant with additional script - Update GitHub Actions workflow to build base image locally (not published) - Both final images (scip-ruby and autoindex) are published to Docker Hub - New image can be used in CI: docker run -v $(pwd):/sources sourcegraph/scip-ruby Amp-Thread-ID: https://ampcode.com/threads/T-93250ea7-f00b-492f-ba56-04da7ddfe7d9 Co-authored-by: Amp --- .github/workflows/publish-docker.yml | 28 +++++++++++++++++++++- Dockerfile | 8 +++++++ Dockerfile.autoindex | 17 ++++---------- Dockerfile.base | 35 ++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 13 deletions(-) create mode 100644 Dockerfile create mode 100644 Dockerfile.base diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml index 4e55ab168..dcc1a1d79 100644 --- a/.github/workflows/publish-docker.yml +++ b/.github/workflows/publish-docker.yml @@ -42,14 +42,40 @@ jobs: with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - - name: Build and push + - name: Build base image (not published) + id: docker_build_base + uses: docker/build-push-action@v6 + with: + file: Dockerfile.base + push: false + load: true + build-args: | + SCIP_RUBY_VERSION=${{ env.PATCH }} + tags: | + scip-ruby-base:${{ env.PATCH }} + - name: Build and push autoindex image id: docker_build_autoindex uses: docker/build-push-action@v6 with: file: Dockerfile.autoindex push: true + build-args: | + BASE_TAG=${{ env.PATCH }} tags: | sourcegraph/scip-ruby:autoindex sourcegraph/scip-ruby:autoindex-${{ env.PATCH }} sourcegraph/scip-ruby:autoindex-${{ env.MINOR }} sourcegraph/scip-ruby:autoindex-${{ env.MAJOR }} + - name: Build and push scip-ruby image + id: docker_build_scip_ruby + uses: docker/build-push-action@v6 + with: + file: Dockerfile + push: true + build-args: | + BASE_TAG=${{ env.PATCH }} + tags: | + sourcegraph/scip-ruby:latest + sourcegraph/scip-ruby:${{ env.PATCH }} + sourcegraph/scip-ruby:${{ env.MINOR }} + sourcegraph/scip-ruby:${{ env.MAJOR }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..80b7c3494 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +# Build from the base image (local, not published) +ARG BASE_TAG +FROM scip-ruby-base:${BASE_TAG} + +# This Docker image provides scip-ruby for CI/CD pipelines + +# Default command is to run scip-ruby +CMD ["scip-ruby"] diff --git a/Dockerfile.autoindex b/Dockerfile.autoindex index 2dbd67e5d..44aa7e8e8 100644 --- a/Dockerfile.autoindex +++ b/Dockerfile.autoindex @@ -1,20 +1,13 @@ -FROM --platform=linux/amd64 ruby:2.7.6-alpine3.16@sha256:b014cf3e792d7130daec772241a211c40be009fc7f00e2b728ffe26805649575 +# Build from the base image (local, not published) +ARG BASE_TAG +FROM scip-ruby-base:${BASE_TAG} # This Docker image is meant for auto-indexing support in Sourcegraph # and is not recommended for third-party use. -# gcompat is a glibc-musl compat library (scip-ruby links in glibc) -# Other deps are to help build C extensions in gems. -RUN apk add --no-cache bash wget make libstdc++ gcc g++ automake autoconf gcompat git - -# Use a release binary instead of building from source -# because release builds are very time-consuming. -# -# The release version is verified by tools/scripts/publish-scip-ruby.sh -RUN wget https://github.com/sourcegraph/scip-ruby/releases/download/scip-ruby-v0.4.6/scip-ruby-x86_64-linux -O /usr/bin/scip-ruby && chmod +x /usr/bin/scip-ruby - +# Copy and install the autoindex script COPY scip_indexer/autoindex.sh /usr/bin/scip-ruby-autoindex - RUN chmod +x /usr/bin/scip-ruby-autoindex +# Default command is shell for autoindex operations CMD ["/bin/sh"] diff --git a/Dockerfile.base b/Dockerfile.base new file mode 100644 index 000000000..ea7483fea --- /dev/null +++ b/Dockerfile.base @@ -0,0 +1,35 @@ +FROM --platform=linux/amd64 \ + ruby:2.7.6-alpine3.16@sha256:b014cf3e792d7130daec772241a211c40be009fc7f00e2b728ffe26805649575 + +# This is the base Docker image for scip-ruby with common dependencies + +# Version argument to be passed during build +ARG SCIP_RUBY_VERSION + +# gcompat is a glibc-musl compat library (scip-ruby links in glibc) +# Other deps are to help build C extensions in gems. +RUN apk add --no-cache \ + bash \ + wget \ + make \ + libstdc++ \ + gcc \ + g++ \ + automake \ + autoconf \ + gcompat \ + git + +# Use a release binary instead of building from source +# because release builds are very time-consuming. +# +# The release version is verified by tools/scripts/publish-scip-ruby.sh +# The binary at this version is guaranteed to exist because this workflow runs either: +# 1. Manually with a specific tag that already has a release +# 2. After the Release workflow completes (which creates the release and uploads the binary) +RUN wget https://github.com/sourcegraph/scip-ruby/releases/download/scip-ruby-v${SCIP_RUBY_VERSION}/scip-ruby-x86_64-linux \ + -O /usr/bin/scip-ruby && \ + chmod +x /usr/bin/scip-ruby + +# Set working directory for sources +WORKDIR /sources From fa8c4373d09b71b65af87be8b3af2d252762f141 Mon Sep 17 00:00:00 2001 From: jupblb Date: Tue, 9 Sep 2025 09:38:56 +0200 Subject: [PATCH 2/2] Add validation for SCIP_RUBY_VERSION build arg in Dockerfile.base Amp-Thread-ID: https://ampcode.com/threads/T-439e5735-e594-4e46-a41a-ca91575956a7 Co-authored-by: Amp --- Dockerfile.base | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Dockerfile.base b/Dockerfile.base index ea7483fea..5dc3605a9 100644 --- a/Dockerfile.base +++ b/Dockerfile.base @@ -6,6 +6,10 @@ FROM --platform=linux/amd64 \ # Version argument to be passed during build ARG SCIP_RUBY_VERSION +# Fail if SCIP_RUBY_VERSION is not provided +RUN test -n "${SCIP_RUBY_VERSION}" || \ + (echo "ERROR: SCIP_RUBY_VERSION build arg is required" && exit 1) + # gcompat is a glibc-musl compat library (scip-ruby links in glibc) # Other deps are to help build C extensions in gems. RUN apk add --no-cache \