Skip to content

Commit

Permalink
Merge pull request #102 from bcgov/feature/terraform-travis-commit
Browse files Browse the repository at this point in the history
Feature/terraform travis commit
  • Loading branch information
BrandonSharratt authored Mar 7, 2019
2 parents a3deceb + acd6edb commit 113436d
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 63 deletions.
35 changes: 23 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ matrix:
stage: "APIs"
language: node_js
node_js:
- "node"
- "lts/*"
cache: npm
addons:
apt:
Expand Down Expand Up @@ -61,7 +61,9 @@ matrix:
cd /home/travis/build/bcgov/OCWA/microservices/forumApi
npm test
- helm lint helm/forum-api
- bash docker_quayio_push
- |-
cd /home/travis/build/bcgov/OCWA/microservices/forumApi
bash docker_quayio_push ocwa_forum_api
- |-
cd /home/travis/build/bcgov/OCWA
PATH=`pwd`/${SONAR_APP}-${SONAR_VERSION}/bin:$PATH
Expand All @@ -81,7 +83,7 @@ matrix:
stage: "APIs"
language: node_js
node_js:
- "node"
- "lts/*"
cache: npm
addons:
apt:
Expand Down Expand Up @@ -149,7 +151,9 @@ matrix:
sleep 15
npm test
- helm lint helm/request-api
- bash docker_quayio_push
- |-
cd /home/travis/build/bcgov/OCWA/microservices/requestApi
bash docker_quayio_push ocwa_request_api
- |-
cd /home/travis/build/bcgov/OCWA
PATH=`pwd`/${SONAR_APP}-${SONAR_VERSION}/bin:$PATH
Expand Down Expand Up @@ -202,11 +206,12 @@ matrix:
cd /home/travis/build/bcgov/OCWA/microservices/policyApi
cp config/default.json.template config/default.json
sudo pip3 install -e .
- sudo pytest
- sudo coverage run --branch --source=db,v1 -m pytest
- sudo coverage xml
- helm lint helm/policy-api
- bash docker_quayio_push
- |-
cd /home/travis/build/bcgov/OCWA/microservices/policyApi
helm lint helm/policy-api
bash docker_quayio_push ocwa_policy_api
- |-
cd /home/travis/build/bcgov/OCWA
PATH=`pwd`/${SONAR_APP}-${SONAR_VERSION}/bin:$PATH
Expand Down Expand Up @@ -269,8 +274,10 @@ matrix:
sudo pip3 install -e .
- sudo coverage run --branch --source=db,v1,validator -m pytest
- sudo coverage xml
- helm lint helm/validate-api
- bash docker_quayio_push
- |-
cd /home/travis/build/bcgov/OCWA/microservices/validateApi
helm lint helm/validate-api
bash docker_quayio_push ocwa_validate_api
- |-
cd /home/travis/build/bcgov/OCWA
PATH=`pwd`/${SONAR_APP}-${SONAR_VERSION}/bin:$PATH
Expand All @@ -290,7 +297,7 @@ matrix:
stage: "Frontend"
language: node_js
node_js:
- "node"
- "lts/*"
cache: npm
addons:
apt:
Expand Down Expand Up @@ -323,8 +330,10 @@ matrix:
- npm ci
- npm audit
- npm test
- helm lint helm/ocwa-frontend
- bash docker_quayio_push ocwa_frontend
- |-
cd /home/travis/build/bcgov/OCWA/frontend
helm lint helm/ocwa-frontend
bash docker_quayio_push ocwa_frontend
- |-
cd /home/travis/build/bcgov/OCWA
sonar-scanner -Dsonar.login=$SONAR_TOKEN -Dproject.settings=sonar-project.properties -Dsonar.projectKey=ocwa_frontend -Dsonar.projectName="OCWA Frontend" -Dsonar.modules=frontend
Expand Down Expand Up @@ -372,6 +381,7 @@ matrix:
cd /home/travis/build/bcgov/OCWA/terraform
mkdir _tmp
cp terraform.tfvars.example terraform.tfvars
python2 scripts/prepare_images_variable.py
- terraform init
- terraform apply -var hostRootPath=`pwd`/_tmp -auto-approve

Expand All @@ -392,6 +402,7 @@ matrix:
sudo chmod +x Katalon_Studio/katalon
sudo chmod -R 777 Katalon_Studio
# Check that the install lifecycle worked
- docker images --digests
- docker ps

script:
Expand Down
24 changes: 15 additions & 9 deletions frontend/docker_quayio_push
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#!/bin/bash

#make sure in the right directory
cd /home/travis/build/bcgov/OCWA/frontend

QUAYIO_REPO=$1
QUAYIO_BASE="quay.io/ikethecoder"

echo "Logging into Quay..."
echo "$QUAYIO_PASSWORD" | docker login -u "$QUAYIO_USERNAME" --password-stdin quay.io
echo "logged in to quay, building now";
docker build -t quay.io/ikethecoder/$QUAYIO_REPO .
echo "dockerfile built pushing now";
docker push quay.io/ikethecoder/$QUAYIO_REPO
echo "push to quay done successfully";

echo "Building Docker image..."
docker build -t $QUAYIO_BASE/$QUAYIO_REPO .

echo "Pushing image $QUAYIO_REPO to Quay..."
docker push $QUAYIO_BASE/$QUAYIO_REPO
if [ ! -z "$TRAVIS_BRANCH" ]; then
echo "Tagging image $QUAYIO_REPO with ${TRAVIS_BRANCH/\//-} on Quay..."
docker tag $QUAYIO_BASE/$QUAYIO_REPO $QUAYIO_BASE/$QUAYIO_REPO:${TRAVIS_BRANCH/\//-}
docker push $QUAYIO_BASE/$QUAYIO_REPO:${TRAVIS_BRANCH/\//-}
fi

echo "Docker image push completed"
23 changes: 15 additions & 8 deletions microservices/forumApi/docker_quayio_push
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
#!/bin/bash
QUAYIO_REPO=$1
QUAYIO_BASE="quay.io/ikethecoder"

#make sure in the right directory
cd /home/travis/build/bcgov/OCWA/microservices/forumApi
echo "Logging into Quay..."
echo "$QUAYIO_PASSWORD" | docker login -u "$QUAYIO_USERNAME" --password-stdin quay.io

echo "Building Docker image..."
docker build -t $QUAYIO_BASE/$QUAYIO_REPO .

echo "$QUAYIO_PASSWORD" | docker login -u "$QUAYIO_USERNAME" --password-stdin quay.io
echo "logged in, building now";
docker build -t quay.io/ikethecoder/ocwa_forum_api .
echo "dockerfile built pushing now";
docker push quay.io/ikethecoder/ocwa_forum_api
echo "push done successfully";
echo "Pushing image $QUAYIO_REPO to Quay..."
docker push $QUAYIO_BASE/$QUAYIO_REPO
if [ ! -z "$TRAVIS_BRANCH" ]; then
echo "Tagging image $QUAYIO_REPO with ${TRAVIS_BRANCH/\//-} on Quay..."
docker tag $QUAYIO_BASE/$QUAYIO_REPO $QUAYIO_BASE/$QUAYIO_REPO:${TRAVIS_BRANCH/\//-}
docker push $QUAYIO_BASE/$QUAYIO_REPO:${TRAVIS_BRANCH/\//-}
fi

echo "Docker image push completed"
23 changes: 15 additions & 8 deletions microservices/policyApi/docker_quayio_push
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
#!/bin/bash
QUAYIO_REPO=$1
QUAYIO_BASE="quay.io/ikethecoder"

#make sure in the right directory
cd /home/travis/build/bcgov/OCWA/microservices/policyApi
echo "Logging into Quay..."
echo "$QUAYIO_PASSWORD" | docker login -u "$QUAYIO_USERNAME" --password-stdin quay.io

echo "Building Docker image..."
docker build -t $QUAYIO_BASE/$QUAYIO_REPO .

echo "$QUAYIO_PASSWORD" | docker login -u "$QUAYIO_USERNAME" --password-stdin quay.io
echo "logged in, building now";
docker build -t quay.io/ikethecoder/ocwa_policy_api .
echo "dockerfile built pushing now";
docker push quay.io/ikethecoder/ocwa_policy_api
echo "push done successfully";
echo "Pushing image $QUAYIO_REPO to Quay..."
docker push $QUAYIO_BASE/$QUAYIO_REPO
if [ ! -z "$TRAVIS_BRANCH" ]; then
echo "Tagging image $QUAYIO_REPO with ${TRAVIS_BRANCH/\//-} on Quay..."
docker tag $QUAYIO_BASE/$QUAYIO_REPO $QUAYIO_BASE/$QUAYIO_REPO:${TRAVIS_BRANCH/\//-}
docker push $QUAYIO_BASE/$QUAYIO_REPO:${TRAVIS_BRANCH/\//-}
fi

echo "Docker image push completed"
23 changes: 15 additions & 8 deletions microservices/requestApi/docker_quayio_push
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
#!/bin/bash
QUAYIO_REPO=$1
QUAYIO_BASE="quay.io/ikethecoder"

#make sure in the right directory
cd /home/travis/build/bcgov/OCWA/microservices/requestApi
echo "Logging into Quay..."
echo "$QUAYIO_PASSWORD" | docker login -u "$QUAYIO_USERNAME" --password-stdin quay.io

echo "Building Docker image..."
docker build -t $QUAYIO_BASE/$QUAYIO_REPO .

echo "$QUAYIO_PASSWORD" | docker login -u "$QUAYIO_USERNAME" --password-stdin quay.io
echo "logged in, building now";
docker build -t quay.io/ikethecoder/ocwa_request_api .
echo "dockerfile built pushing now";
docker push quay.io/ikethecoder/ocwa_request_api
echo "push done successfully";
echo "Pushing image $QUAYIO_REPO to Quay..."
docker push $QUAYIO_BASE/$QUAYIO_REPO
if [ ! -z "$TRAVIS_BRANCH" ]; then
echo "Tagging image $QUAYIO_REPO with ${TRAVIS_BRANCH/\//-} on Quay..."
docker tag $QUAYIO_BASE/$QUAYIO_REPO $QUAYIO_BASE/$QUAYIO_REPO:${TRAVIS_BRANCH/\//-}
docker push $QUAYIO_BASE/$QUAYIO_REPO:${TRAVIS_BRANCH/\//-}
fi

echo "Docker image push completed"
23 changes: 15 additions & 8 deletions microservices/validateApi/docker_quayio_push
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
#!/bin/bash
QUAYIO_REPO=$1
QUAYIO_BASE="quay.io/ikethecoder"

#make sure in the right directory
cd /home/travis/build/bcgov/OCWA/microservices/validateApi
echo "Logging into Quay..."
echo "$QUAYIO_PASSWORD" | docker login -u "$QUAYIO_USERNAME" --password-stdin quay.io

echo "Building Docker image..."
docker build -t $QUAYIO_BASE/$QUAYIO_REPO .

echo "$QUAYIO_PASSWORD" | docker login -u "$QUAYIO_USERNAME" --password-stdin quay.io
echo "logged in, building now";
docker build -t quay.io/ikethecoder/ocwa_validate_api .
echo "dockerfile built pushing now";
docker push quay.io/ikethecoder/ocwa_validate_api
echo "push done successfully";
echo "Pushing image $QUAYIO_REPO to Quay..."
docker push $QUAYIO_BASE/$QUAYIO_REPO
if [ ! -z "$TRAVIS_BRANCH" ]; then
echo "Tagging image $QUAYIO_REPO with ${TRAVIS_BRANCH/\//-} on Quay..."
docker tag $QUAYIO_BASE/$QUAYIO_REPO $QUAYIO_BASE/$QUAYIO_REPO:${TRAVIS_BRANCH/\//-}
docker push $QUAYIO_BASE/$QUAYIO_REPO:${TRAVIS_BRANCH/\//-}
fi

echo "Docker image push completed"
2 changes: 1 addition & 1 deletion terraform/ocwa_forum_api.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

data "docker_registry_image" "ocwa_forum_api" {
name = "bcgovimages/ocwa_forum_api${var.images["forum_api"]}"
name = "${var.images["owner"]}/ocwa_forum_api${var.images["forum_api"]}"
}

resource "docker_image" "ocwa_forum_api" {
Expand Down
2 changes: 1 addition & 1 deletion terraform/ocwa_frontend.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

data "docker_registry_image" "ocwa_frontend" {
name = "bcgovimages/ocwa_frontend${var.images["frontend"]}"
name = "${var.images["owner"]}/ocwa_frontend${var.images["frontend"]}"
}

resource "docker_image" "ocwa_frontend" {
Expand Down
2 changes: 1 addition & 1 deletion terraform/ocwa_policy_api.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

data "docker_registry_image" "ocwa_policy_api" {
name = "bcgovimages/ocwa_policy_api${var.images["policy_api"]}"
name = "${var.images["owner"]}/ocwa_policy_api${var.images["policy_api"]}"
}

resource "docker_image" "ocwa_policy_api" {
Expand Down
2 changes: 1 addition & 1 deletion terraform/ocwa_request_api.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

data "docker_registry_image" "ocwa_request_api" {
name = "bcgovimages/ocwa_request_api${var.images["request_api"]}"
name = "${var.images["owner"]}/ocwa_request_api${var.images["request_api"]}"
}

resource "docker_image" "ocwa_request_api" {
Expand Down
2 changes: 1 addition & 1 deletion terraform/ocwa_validate_api.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

data "docker_registry_image" "ocwa_validate_api" {
name = "bcgovimages/ocwa_validate_api${var.images["validate_api"]}"
name = "${var.images["owner"]}/ocwa_validate_api${var.images["validate_api"]}"
}

resource "docker_image" "ocwa_validate_api" {
Expand Down
11 changes: 6 additions & 5 deletions terraform/report.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ resource "local_file" "report_script" {
data "template_file" "terraform_lock" {
template = "${file("${path.module}/scripts/terraform.lock.tpl")}"
vars = {
requestApiDigest = "${data.docker_registry_image.ocwa_request_api.sha256_digest}"
policyApiDigest = "${data.docker_registry_image.ocwa_policy_api.sha256_digest}"
validateApiDigest = "${data.docker_registry_image.ocwa_validate_api.sha256_digest}"
forumApiDigest = "${data.docker_registry_image.ocwa_forum_api.sha256_digest}"
frontendDigest = "${data.docker_registry_image.ocwa_frontend.sha256_digest}"
owner = "${var.images["owner"]}"
requestApiDigest = "@${data.docker_registry_image.ocwa_request_api.sha256_digest}"
policyApiDigest = "@${data.docker_registry_image.ocwa_policy_api.sha256_digest}"
validateApiDigest = "@${data.docker_registry_image.ocwa_validate_api.sha256_digest}"
forumApiDigest = "@${data.docker_registry_image.ocwa_forum_api.sha256_digest}"
frontendDigest = "@${data.docker_registry_image.ocwa_frontend.sha256_digest}"
}
}

Expand Down
21 changes: 21 additions & 0 deletions terraform/scripts/prepare_images_variable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
from string import Template

template = """
images = {
owner = "quay.io/ikethecoder"
request_api = ":${TAG}"
policy_api = ":${TAG}"
validate_api = ":${TAG}"
forum_api = ":${TAG}"
frontend = ":${TAG}"
minio = ":latest"
tusd = ":latest"
}
"""

s = Template(template)

with open('terraform.auto.tfvars', 'w') as the_file:
the_file.write(s.substitute(TAG=os.environ['TRAVIS_BRANCH'].replace('/', '-')))
1 change: 1 addition & 0 deletions terraform/scripts/terraform.lock.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

images = {
owner = "${owner}"
request_api = "${requestApiDigest}"
policy_api = "${policyApiDigest}"}
validate_api = "${validateApiDigest}"}
Expand Down
1 change: 1 addition & 0 deletions terraform/terraform.tfvars.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ sslCertificate = "/ssl/example.crt"
sslCertificateKey = "/ssl/example.key"

images = {
owner = "bcgovimages"
request_api = ":edge"
validate_api = ":edge"
forum_api = ":edge"
Expand Down

0 comments on commit 113436d

Please sign in to comment.