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..5dc3605a9 --- /dev/null +++ b/Dockerfile.base @@ -0,0 +1,39 @@ +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 + +# 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 \ + 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