summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Kocoloski <kocolosk@apache.org>2022-02-26 23:19:46 -0500
committerAdam Kocoloski <kocolosk@apache.org>2022-02-26 23:19:46 -0500
commit64638321b7f4b8d99ad3a648a675f7bb9bca7543 (patch)
tree590ff370349b87b79ce29b8aafe4ca97e1c5f1f1
parent237f5a92e3e5b2376424307601db7634040d6fca (diff)
downloadcouchdb-64638321b7f4b8d99ad3a648a675f7bb9bca7543.tar.gz
Upgrade devcontainer to be usable for Jenkins PRs
Still a work in progress, but the idea is that developers should be working with the same base image that we use to validate Pull Requests in CI. I've also started to add a GitHub Action that could publish these devcontainer images on a regularly scheduled basis to pick up fixes and new patch releases from upstream.
-rw-r--r--.devcontainer/Dockerfile74
-rw-r--r--.devcontainer/create_cluster_file.bash52
-rw-r--r--.devcontainer/docker-compose.yaml41
-rwxr-xr-x.devcontainer/install_dependencies.sh75
-rw-r--r--.github/workflows/devcontainer-builder.yml57
5 files changed, 236 insertions, 63 deletions
diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
index 3272dad05..5befb138c 100644
--- a/.devcontainer/Dockerfile
+++ b/.devcontainer/Dockerfile
@@ -1,45 +1,33 @@
-ARG FDB_VERSION
-ARG ELIXIR_VERSION
-
-# Grab fdbcli and client library from same image as server
-FROM foundationdb/foundationdb:${FDB_VERSION} as fdb
-
-# Debian image with Erlang + Elixir installed (we need elixir for test suite)
-FROM elixir:${ELIXIR_VERSION}
-
-# The FROM directive above sweeps out the ARGs so we need to re-declare here
-# in order to use it again to download the FDB client package
-ARG FDB_VERSION
-
-# Install SpiderMonkey 60 and tell CouchDB to use it in configure
-ARG SM_VSN
-ENV SM_VSN=${SM_VSN:-60}
-
-RUN set -ex; \
- wget https://www.foundationdb.org/downloads/${FDB_VERSION}/ubuntu/installers/foundationdb-clients_${FDB_VERSION}-1_amd64.deb; \
- mkdir /var/lib/foundationdb; \
- dpkg -i foundationdb-clients_${FDB_VERSION}-1_amd64.deb
-
-# Use NodeSource binaries for Node.js (Fauxton dependency)
-RUN set -ex; \
- curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -; \
- echo "deb https://deb.nodesource.com/node_10.x buster main" | tee /etc/apt/sources.list.d/nodesource.list; \
- echo "deb-src https://deb.nodesource.com/node_10.x buster main" | tee -a /etc/apt/sources.list.d/nodesource.list
-
-RUN set -ex; \
- apt-get update; \
- apt-get install -y --no-install-recommends \
- dnsutils \
- libmozjs-${SM_VSN}-dev \
- libicu-dev \
- python3-venv \
- python3-pip \
- python3-sphinx \
- nodejs
-
-# Documentation theme
-RUN pip3 install sphinx_rtd_theme
-
-COPY --from=fdb /var/fdb/scripts/create_cluster_file.bash /usr/local/bin/
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+ARG ERLANG_VSN
+FROM erlang:${ERLANG_VSN}
+
+ARG ERLANG_VSN
+ARG FDB_VSN
+ARG NODE_VSN
+
+# Create Jenkins user and group for usage in CI
+RUN groupadd --gid 910 jenkins; \
+ useradd --uid 910 --gid jenkins --create-home jenkins
+
+COPY install_dependencies.sh /tmp/
+
+RUN ERLANG_VSN=${ERLANG_VSN} FDB_VSN=${FDB_VSN} NODE_VSN=${NODE_VSN} /tmp/install_dependencies.sh
+
+# Allow Jenkins to sudo
+RUN echo "jenkins ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/jenkins
+
+COPY create_cluster_file.bash /usr/local/bin/
CMD sleep infinity
diff --git a/.devcontainer/create_cluster_file.bash b/.devcontainer/create_cluster_file.bash
new file mode 100644
index 000000000..c1bb959b8
--- /dev/null
+++ b/.devcontainer/create_cluster_file.bash
@@ -0,0 +1,52 @@
+#! /bin/bash
+
+#
+# create_cluster_file.bash
+#
+# This source file is part of the FoundationDB open source project
+#
+# Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# This script creates a cluster file for a server or client.
+# This takes the cluster file path from the FDB_CLUSTER_FILE
+# environment variable, with a default of /etc/foundationdb/fdb.cluster
+#
+# The name of the coordinator must be defined in the FDB_COORDINATOR environment
+# variable, and it must be a name that can be resolved through DNS.
+
+function create_cluster_file() {
+ FDB_CLUSTER_FILE=${FDB_CLUSTER_FILE:-/etc/foundationdb/fdb.cluster}
+ mkdir -p $(dirname $FDB_CLUSTER_FILE)
+
+ if [[ -n "$FDB_CLUSTER_FILE_CONTENTS" ]]; then
+ echo "$FDB_CLUSTER_FILE_CONTENTS" > $FDB_CLUSTER_FILE
+ elif [[ -n $FDB_COORDINATOR ]]; then
+ coordinator_ip=$(dig +short $FDB_COORDINATOR)
+ if [[ -z "$coordinator_ip" ]]; then
+ echo "Failed to look up coordinator address for $FDB_COORDINATOR" 1>&2
+ exit 1
+ fi
+ coordinator_port=${FDB_COORDINATOR_PORT:-4500}
+ echo "docker:docker@$coordinator_ip:$coordinator_port" > $FDB_CLUSTER_FILE
+ else
+ echo "FDB_COORDINATOR environment variable not defined" 1>&2
+ exit 1
+ fi
+}
+
+if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
+ create_cluster_file "$@"
+fi
diff --git a/.devcontainer/docker-compose.yaml b/.devcontainer/docker-compose.yaml
index 79f1da775..ce0b0b79c 100644
--- a/.devcontainer/docker-compose.yaml
+++ b/.devcontainer/docker-compose.yaml
@@ -1,33 +1,33 @@
services:
couch:
+ # Select a pre-built image hosted on GHCR
+ # image: ghcr.io/apache/couchdb:devcontainer-erlang-24-fdb-6.3.23
+
+ # Alternatively, build your own image on-demand
build:
context: .
dockerfile: Dockerfile
args:
- # Base image for Erlang and Elixir. Useful choices include:
- # 1.11 -> Erlang 23, Debian Buster
- # 1.10 -> Erlang 22, Debian Buster
- # 1.9 -> Erlang 22, Debian Buster
- #
- # Older versions based on Debian Stretch will not include
- # SpiderMonkey 60, which the Dockerfile expects to be able
- # to install via apt-get.
- ELIXIR_VERSION: "1.10"
-
- # SpiderMonkey version to install with apt-get
- SM_VSN: "60"
-
- # This should always match the value in fdb.image
- FDB_VERSION: "6.2.28"
+ # The Erlang version determines our base image, which means it
+ # implicitly selects versions for ICU + SpiderMonkey as well.
+ ERLANG_VSN: "24"
+
+ # This selects the FoundationDB client version. Typically you'd
+ # want it to match the server version in fdb.image below.
+ FDB_VSN: "6.3.23"
+
+ # The Fauxton UI has a Node.js build-time dependency, most of
+ # the time there's no reason to change this.
+ NODE_VSN: "14"
environment:
# This needs to match the name of the FoundationDB service below
FDB_COORDINATOR: fdb
- # The location where the Dockerfile installs the FDB cluster file
- # retrieved from the `fdb` image. CouchDB looks for the cluster file in
- # this location by default. If you want to install it somewhere else you
- # you need to change "[erlfdb] cluster_file" and ERL_ZFLAGS to match.
+ # The location where the FDB cluster file is created on container
+ # startup. CouchDB looks for the cluster file in this location by
+ # default. If you want to install it somewhere else you need to
+ # change "[erlfdb] cluster_file" and ERL_ZFLAGS to match.
FDB_CLUSTER_FILE: /usr/local/etc/foundationdb/fdb.cluster
# The test suite will default to trying to start its own fdbserver
@@ -49,4 +49,5 @@ services:
network_mode: service:fdb
fdb:
- image: foundationdb/foundationdb:6.2.28
+ # This is the version of the FDB server that will run alongside CouchDB
+ image: foundationdb/foundationdb:6.3.23
diff --git a/.devcontainer/install_dependencies.sh b/.devcontainer/install_dependencies.sh
new file mode 100755
index 000000000..c58739cb1
--- /dev/null
+++ b/.devcontainer/install_dependencies.sh
@@ -0,0 +1,75 @@
+#!/usr/bin/env bash
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -ex
+
+. /etc/os-release 2>/dev/null || true
+
+# Choose Elixir version automatically based on Erlang version
+if [ -z ${ELIXIR_VSN} ]; then
+ if [[ ${ERLANG_VSN} =~ ^20 ]]; then
+ ELIXIR_VSN='v1.9.4'
+ elif [[ ${ERLANG_VSN} =~ ^21 ]]; then
+ ELIXIR_VSN='v1.11.4'
+ elif [[ ${ERLANG_VSN} =~ ^2[234] ]]; then
+ ELIXIR_VSN='v1.12.3'
+ else
+ ELIXIR_VSN='v1.13.3'
+ fi
+fi
+
+# SpiderMonkey likes to bake the version into the package name
+if [ "${VERSION_CODENAME}" == "stretch" ]; then
+ # We provide our own build of SM 1.8.5 for ancient distros
+ curl https://couchdb.apache.org/repo/keys.asc | gpg --dearmor | tee /usr/share/keyrings/couchdb-archive-keyring.gpg >/dev/null 2>&1
+ echo "deb [signed-by=/usr/share/keyrings/couchdb-archive-keyring.gpg] https://apache.jfrog.io/artifactory/couchdb-deb/ stretch main" \
+ | tee /etc/apt/sources.list.d/couchdb.list >/dev/null
+ spidermonkey_pkg='couch-libmozjs185-dev'
+elif [ "${VERSION_CODENAME}" == "buster" ]; then
+ spidermonkey_pkg='libmozjs-60-dev'
+elif [ "${VERSION_CODENAME}" == "bullseye" ]; then
+ spidermonkey_pkg='libmozjs-78-dev'
+fi
+
+# Activate NodeSource repo for Node.js (Fauxton dependency)
+wget -q https://deb.nodesource.com/setup_${NODE_VSN}.x
+/bin/bash setup_${NODE_VSN}.x
+rm setup_${NODE_VSN}.x
+
+apt-get install --no-install-recommends -y \
+ sudo \
+ dnsutils \
+ python3-pip \
+ python3-sphinx \
+ python3-venv \
+ libicu-dev \
+ $spidermonkey_pkg \
+ nodejs
+
+npm install npm@latest -g --unsafe-perm
+
+# Documentation theme
+pip3 install sphinx_rtd_theme
+
+# Elixir
+wget -q https://github.com/elixir-lang/elixir/releases/download/${ELIXIR_VSN}/Precompiled.zip
+unzip -qq Precompiled.zip -d /usr/local
+rm Precompiled.zip
+
+# FoundationDB client
+wget -q https://github.com/apple/foundationdb/releases/download/${FDB_VSN}/foundationdb-clients_${FDB_VSN}-1_amd64.deb
+dpkg -i ./foundationdb*deb
+rm -rf ./foundationdb*deb
+
+apt-get clean
diff --git a/.github/workflows/devcontainer-builder.yml b/.github/workflows/devcontainer-builder.yml
new file mode 100644
index 000000000..1e0edfcf9
--- /dev/null
+++ b/.github/workflows/devcontainer-builder.yml
@@ -0,0 +1,57 @@
+name: Dev Environment Builder
+
+on:
+ workflow_dispatch:
+ inputs:
+ erlangVersion:
+ description: 'Erlang/OTP Version'
+ required: true
+ default: '24'
+ fdbVersion:
+ description: 'FoundationDB Client Version'
+ required: true
+ default: '6.2.28'
+ platforms:
+ description: 'Target Platforms'
+ required: true
+ default: 'linux/amd64'
+
+jobs:
+ build-and-push-image:
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Authenticate to container registry
+ uses: docker/login-action@v1
+ with:
+ registry: ghcr.io
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ - name: Set up Docker Buildx
+ id: buildx
+ uses: docker/setup-buildx-action@v1
+
+ - name: Inspect builder
+ run: |
+ echo "Name: ${{ steps.buildx.outputs.name }}"
+ echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
+ echo "Status: ${{ steps.buildx.outputs.status }}"
+ echo "Flags: ${{ steps.buildx.outputs.flags }}"
+ echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
+
+ - name: Build and push
+ uses: docker/build-push-action@v2
+ with:
+ context: "{{defaultContext}}:.devcontainer"
+
+ push: true
+
+ platforms: ${{ github.event.inputs.platforms }}
+
+ build-args: |
+ ERLANG_VSN=${{ github.event.inputs.erlangVersion }}
+ FDB_VSN=${{ github.event.inputs.fdbVersion }}
+ NODE_VSN=14
+ tags: |
+ ghcr.io/${{ github.repository }}:devcontainer-erlang-${{ github.event.inputs.erlangVersion }}-fdb-${{ github.event.inputs.fdbVersion }}