Skip to content

Commit

Permalink
Merge pull request #879 from amazeeio/841-disable-git-sha-injection
Browse files Browse the repository at this point in the history
841 disable git sha injection
  • Loading branch information
Schnitzel committed Feb 26, 2019
2 parents ad8948c + 5d7a961 commit 3798573
Show file tree
Hide file tree
Showing 21 changed files with 424 additions and 8 deletions.
6 changes: 6 additions & 0 deletions docs/using_lagoon/lagoon_yml.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ The `.lagoon.yml` file must be placed at the root of your git repository.
```
docker-compose-yaml: docker-compose.yml
environment_variables:
git_sha: 'true'
tasks:
pre-rollout:
- run:
Expand Down Expand Up @@ -77,6 +80,9 @@ This allows you to define the behaviour of the automatic creates routes (NOT the
* `Redirect` will redirect any http requests to https
* `None` will mean a route for http will _not_ be created, and no redirect

### `environment_variables.git_sha`
This setting allows you to enable injecting the deployed git SHA into your project as an environment variable. By default this is disabled, setting the value to `true` then sets the SHA as the environment variable `LAGOON_GIT_SHA`.

## Tasks

There are different type of tasks you can define, they differ when exactly they are executed in a build flow:
Expand Down
10 changes: 8 additions & 2 deletions images/oc-build-deploy-dind/build-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ else
/oc-build-deploy/scripts/git-checkout-pull.sh "$SOURCE_REPOSITORY" "$GIT_REF"
fi

LAGOON_GIT_SHA=`git rev-parse HEAD`

if [[ -n "$SUBFOLDER" ]]; then
cd $SUBFOLDER
fi
Expand All @@ -28,6 +26,14 @@ if [ ! -f .lagoon.yml ]; then
echo "no .lagoon.yml file found"; exit 1;
fi

INJECT_GIT_SHA=$(cat .lagoon.yml | shyaml get-value environment_variables.git_sha false)
if [ "$INJECT_GIT_SHA" == "true" ]
then
LAGOON_GIT_SHA=`git rev-parse HEAD`
else
LAGOON_GIT_SHA="0000000000000000000000000000000000000000"
fi

DOCKER_REGISTRY_TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)

docker login -u=jenkins -p="${DOCKER_REGISTRY_TOKEN}" ${OPENSHIFT_REGISTRY}
Expand Down
5 changes: 4 additions & 1 deletion tests/files/drupal8-mariadb/.lagoon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ docker-compose-yaml: docker-compose.yml
endpoint: 192.168.99.1:2020
api: 192.168.99.1:3000

environment_variables:
git_sha: 'true'

tasks:
post-rollout:
- run:
Expand Down Expand Up @@ -47,4 +50,4 @@ environments:
- name: drush cron
schedule: "1 * * * *"
command: drush cron
service: cli
service: cli
5 changes: 4 additions & 1 deletion tests/files/drupal8-postgres/.lagoon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ docker-compose-yaml: docker-compose.yml
endpoint: 192.168.99.1:2020
api: 192.168.99.1:3000

environment_variables:
git_sha: 'true'

tasks:
post-rollout:
- run:
Expand Down Expand Up @@ -40,4 +43,4 @@ environments:
- name: drush cron
schedule: "1 * * * *"
command: drush cron
service: cli
service: cli
3 changes: 3 additions & 0 deletions tests/files/elasticsearch-cluster/.lagoon.yml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
docker-compose-yaml: docker-compose.yml

environment_variables:
git_sha: 'true'
3 changes: 3 additions & 0 deletions tests/files/elasticsearch/.lagoon.yml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
docker-compose-yaml: docker-compose.yml

environment_variables:
git_sha: 'true'
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
docker-compose-yaml: docker-compose.yml

environment_variables:
git_sha: 'true'

routes:
autogenerate:
enabled: 'false'
Expand Down
1 change: 1 addition & 0 deletions tests/files/features-disable-inject-git-sha/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions tests/files/features-disable-inject-git-sha/.lagoon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker-compose-yaml: docker-compose.yml
18 changes: 18 additions & 0 deletions tests/files/features-disable-inject-git-sha/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ARG IMAGE_REPO
FROM ${IMAGE_REPO:-amazeeio}/node:8-builder as builder
COPY package.json yarn.lock /app/
RUN yarn install

FROM ${IMAGE_REPO:-amazeeio}/node:8
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-disable-inject-git-sha/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: node-persistent
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-disable-inject-git-sha/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-disable-inject-git-sha/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 3798573

Please sign in to comment.