CI service ENV variables

Hi All,

I’m trying to build a Solr service that extends the upstream Solr image on docker hub and allows for dynamic creation of both a Solr core and the configuration of a given application. This is done using environment variables.

I borrowed the idea from this repository https://github.com/osulibraries/solr-docker

Here’s is my version of the solr image and related script: https://gitlab.com/surfliner/solr-service-testing/tree/master/docker/solr

Dockerfile contents:

FROM solr:alpine

USER root

RUN apk --no-cache upgrade && \
  apk add --no-cache \
  git

USER $SOLR_USER

COPY ./setup.sh /docker-entrypoint-initdb.d/

setup.sh contents:

#!/bin/bash
set -e

# Exit if the CI environment variables are not set
for var in SOLR_CORE_NAME SOLR_CONFIG_DIR CI_REPOSITORY_URL CI_COMMIT_SHA ; do
  if [ -z "${!var}" ] ; then
    skip_solr_ci="true"
  fi
done

if [ -z "$skip_solr_ci" ] ; then
  git clone "$CI_REPOSITORY_URL" /tmp/repo
  cd /tmp/repo
  git checkout "$CI_COMMIT_SHA"

  echo "Creating Solr core: $SOLR_CORE_NAME..."
  coresdir="/opt/solr/server/solr/mycores"
  mkdir -p $coresdir
  coredir="$coresdir/$SOLR_CORE_NAME"

  if [[ ! -d $coredir ]]; then
    mkdir  -p "$coredir"
    cp -r "/tmp/repo/$SOLR_CONFIG_DIR" "$coredir/conf"
    touch "$coredir/core.properties"
    echo "Successfully created $SOLR_CORE_NAME"
  else
      echo "Core $SOLR_CORE_NAME already exists"
  fi
else
  echo "CI Environment varaibles not set. Proceding with Solr startup..."
fi

And my gitlab-ci file building and trying to use it:

I suppose my tl;dr question is, can a linked service image in Gitlab access the environment variables I’m assuming it can in the setup.sh script? Thanks in advance for any advice/thoughts anyone has. I’m trying to sort out the best approach for dealing with this…