Skip to content

Commit

Permalink
Merge pull request #2156 from shreddedbacon/service-types
Browse files Browse the repository at this point in the history
Add Project/Environment EnvVar overrides for service types
  • Loading branch information
Schnitzel authored Sep 8, 2020
2 parents 90aa598 + 48bab7c commit e762600
Show file tree
Hide file tree
Showing 15 changed files with 555 additions and 0 deletions.
25 changes: 25 additions & 0 deletions images/kubectl-build-deploy-dind/build-deploy-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ done

set -x

set +x # reduce noise in build logs
# Allow the servicetype be overridden by the lagoon API
# This accepts colon separated values like so `SERVICE_NAME:SERVICE_TYPE_OVERRIDE`, and multiple overrides
# separated by commas
# Example 1: mariadb:mariadb-dbaas < tells any docker-compose services named mariadb to use the mariadb-dbaas service type
# Example 2: mariadb:mariadb-dbaas,nginx:nginx-persistent
if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then
LAGOON_SERVICE_TYPES=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_SERVICE_TYPES") | "\(.value)"'))
fi
if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then
LAGOON_SERVICE_TYPES=($(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_SERVICE_TYPES") | "\(.value)"'))
fi
set -x

for COMPOSE_SERVICE in "${COMPOSE_SERVICES[@]}"
do
# The name of the service can be overridden, if not we use the actual servicename
Expand All @@ -79,6 +93,17 @@ do
SERVICE_TYPE=$ENVIRONMENT_SERVICE_TYPE_OVERRIDE
fi

if [ ! -z "$LAGOON_SERVICE_TYPES" ]; then
IFS=',' read -ra LAGOON_SERVICE_TYPES_SPLIT <<< "$LAGOON_SERVICE_TYPES"
for LAGOON_SERVICE_TYPE in "${LAGOON_SERVICE_TYPES_SPLIT[@]}"
do
IFS=':' read -ra LAGOON_SERVICE_TYPE_SPLIT <<< "$LAGOON_SERVICE_TYPE"
if [ "${LAGOON_SERVICE_TYPE_SPLIT[0]}" == "$SERVICE_NAME" ]; then
SERVICE_TYPE=${LAGOON_SERVICE_TYPE_SPLIT[1]}
fi
done
fi

# "mariadb" is a meta service, which allows lagoon to decide itself which of the services to use:
# - mariadb-single (a single mariadb pod)
# - mariadb-dbaas (use the dbaas shared operator)
Expand Down
25 changes: 25 additions & 0 deletions images/oc-build-deploy-dind/build-deploy-docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ declare -A IMAGES_PULL
declare -A IMAGES_BUILD
set -x

set +x # reduce noise in build logs
# Allow the servicetype be overridden by the lagoon API
# This accepts colon separated values like so `SERVICE_NAME:SERVICE_TYPE_OVERRIDE`, and multiple overrides
# separated by commas
# Example 1: mariadb:mariadb-dbaas < tells any docker-compose services named mariadb to use the mariadb-dbaas service type
# Example 2: mariadb:mariadb-dbaas,nginx:nginx-persistent
if [ ! -z "$LAGOON_PROJECT_VARIABLES" ]; then
LAGOON_SERVICE_TYPES=($(echo $LAGOON_PROJECT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_SERVICE_TYPES") | "\(.value)"'))
fi
if [ ! -z "$LAGOON_ENVIRONMENT_VARIABLES" ]; then
LAGOON_SERVICE_TYPES=($(echo $LAGOON_ENVIRONMENT_VARIABLES | jq -r '.[] | select(.name == "LAGOON_SERVICE_TYPES") | "\(.value)"'))
fi
set -x

for COMPOSE_SERVICE in "${COMPOSE_SERVICES[@]}"
do
# The name of the service can be overridden, if not we use the actual servicename
Expand All @@ -82,6 +96,17 @@ do
SERVICE_TYPE=$ENVIRONMENT_SERVICE_TYPE_OVERRIDE
fi

if [ ! -z "$LAGOON_SERVICE_TYPES" ]; then
IFS=',' read -ra LAGOON_SERVICE_TYPES_SPLIT <<< "$LAGOON_SERVICE_TYPES"
for LAGOON_SERVICE_TYPE in "${LAGOON_SERVICE_TYPES_SPLIT[@]}"
do
IFS=':' read -ra LAGOON_SERVICE_TYPE_SPLIT <<< "$LAGOON_SERVICE_TYPE"
if [ "${LAGOON_SERVICE_TYPE_SPLIT[0]}" == "$SERVICE_NAME" ]; then
SERVICE_TYPE=${LAGOON_SERVICE_TYPE_SPLIT[1]}
fi
done
fi

# "mariadb" is a meta service, which allows lagoon to decide itself which of the services to use:
# - mariadb-single (a single mariadb pod)
# - mariadb-shared (use a mariadb shared service broker)
Expand Down
1 change: 1 addition & 0 deletions tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ RUN apk add --no-cache --virtual .build-deps \
ansible==2.8.13 \
PyJWT \
requests \
jmespath \
&& apk del .build-deps

# download, extract and install kubectl binary
Expand Down
1 change: 1 addition & 0 deletions tests/files/features-lagoon-type-override/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
4 changes: 4 additions & 0 deletions tests/files/features-lagoon-type-override/.lagoon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
docker-compose-yaml: docker-compose.yml

environment_variables:
git_sha: 'true'
18 changes: 18 additions & 0 deletions tests/files/features-lagoon-type-override/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ARG IMAGE_REPO
FROM ${IMAGE_REPO:-amazeeio}/node:10-builder as builder
COPY package.json yarn.lock /app/
RUN yarn install

FROM ${IMAGE_REPO:-amazeeio}/node:10
COPY --from=builder /app/node_modules /app/node_modules
COPY . /app/

ARG LAGOON_GIT_SHA=0000000000000000000000000000000000000000
ENV LAGOON_GIT_SHA_BUILDTIME ${LAGOON_GIT_SHA}

ARG LAGOON_GIT_BRANCH=undefined
ENV LAGOON_GIT_BRANCH_BUILDTIME ${LAGOON_GIT_BRANCH}

EXPOSE 3000

CMD ["yarn", "run", "start"]
23 changes: 23 additions & 0 deletions tests/files/features-lagoon-type-override/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '2'
services:
node:
networks:
- amazeeio-network
- default
build:
context: .
dockerfile: Dockerfile
labels:
lagoon.type: none
lagoon.persistent: /files
volumes:
- ./index.js:/app/index.js:delegated
expose:
- "3000"
environment:
- AMAZEEIO_URL=node.docker.amazee.io
- AMAZEEIO=AMAZEEIO
- AMAZEEIO_HTTP_PORT=3000
networks:
amazeeio-network:
external: true
24 changes: 24 additions & 0 deletions tests/files/features-lagoon-type-override/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const express = require('express')
const fs = require('fs');
const app = express()

app.get('/', async function (req, res) {
let result = []
Object.keys(process.env).map(key => {
result.push(`${key}=${process.env[key]}`)
})
result.sort()

try {
result.push(fs.readFileSync('/files/cron.txt').toString());
} catch (e) {
// intentionally left empty
}

res.send(result.join("<br />"))

})

app.listen(3000, function () {
console.log('Example app listening on port 3000!')
})
12 changes: 12 additions & 0 deletions tests/files/features-lagoon-type-override/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "node",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"express": "^4.15.3"
},
"scripts": {
"start": "node index.js"
}
}
Loading

0 comments on commit e762600

Please sign in to comment.