Skip to content

Commit 7e48fa3

Browse files
authored
Merge pull request #40 from oracle-quickstart/develop
Develop - Complete Solution
2 parents 9e56f90 + 09c2071 commit 7e48fa3

File tree

581 files changed

+53732
-456
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

581 files changed

+53732
-456
lines changed

.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
.env
3+
assets
4+
*.tgz
5+
**/build
6+
**/coverage
7+
**/node_modules
8+
**/Makefile

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,8 @@ pkg/
6969
override.tf
7070
override.tf.json
7171
*_override.tf
72-
*_override.tf.json
72+
*_override.tf.json
73+
74+
tnsnames.ora
75+
keystore.jks
76+
truststore.jks

ci/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# MuShop CI
2+
3+
## Wercker Setup
4+
5+
When setting up a new Wercker workflow, keep in mind the following environment variables and pipelines that need to be configured beforehand.
6+
7+
The following global variables need to be set on the Wercker application (the Environment tab):
8+
9+
| Environment variable name | Description | Example |
10+
| --- | --- | --- |
11+
| DOCKER_REPOSITORY | Docker repository name | `phx.ocir.io/{tenancyName}/mushop` |
12+
13+
### Build (`build`)
14+
15+
Build pipeline uses the `internal/docker-build` step to build Docker images for all services.
16+
17+
### Push to Registry (`push-to-registry`)
18+
19+
This pipeline pushes the build Docker images to the registry. The following environment variables need to be set on the pipeline.
20+
21+
| Environment variable name | Description | Example |
22+
| --- | --- | --- |
23+
| DOCKER_USERNAME | Docker registry username | `{tenancyName}/{myUserName}` |
24+
| DOCKER_PASSWORD | Docker registry password | `{myUserPassword}` |
25+
26+
### Testing
27+
28+
Because we have services in multiple languages, we had to separate the pipelines per-language (each pipeline uses a language specific box (e.g. `node`, `golang`)). Another reason we had to do this is because Wercker isn't really set up for a multi-repo - it would work better if we had a separate repo for each component.
29+
30+
We have the following pipelines to run tests - these could be run in parallel after build pipeline completes.
31+
32+
- `test-node-services` - runs unit tests for all NodeJS services
33+
- `test-go-services` - runs unit tests for all Go services
34+
- `test-java-services` - runs unit tests for all Java services
35+
36+
The test pipelines don't require any additional environment variables.
37+
38+
### Deployments
39+
40+
There are two deployment (upgrade) pipelines defined in Wercker
41+
42+
- Test Deployment (`upgrade-test-deployment`)
43+
- Production Deployment (`upgrade-production-deployment`)
44+
45+
Both deployment pipelines are equivalent, the difference is in the environment variables that are set on the pipelines. The variables define which cluster is used for deployment as well as the Helm release name.
46+
47+
| Environment variable name | Description | Example |
48+
| --- | --- | --- |
49+
| HELM_RELEASE_NAME | Helm release name to be upgraded | `mymushop` |
50+
| HELM_TIMEOUT | Helm timeout value | `600` |
51+
| KUBERNETES_SERVER | URL of the Kubernetes server | `https://mykubernetescluster.com:6443` |
52+
| KUBERNETES_TOKEN | User token for the Kubernetes cluster (from `.kube/config`) | `eyJoZWFkZXIiOnsiQXV0a...` |

ci/build.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
4+
# The Universal Permissive License (UPL), Version 1.0
5+
#
6+
7+
# set -ev
8+
9+
PROJECT="mushop"
10+
SRC_DIR=$1
11+
CODE_DIR=$(cd $SRC_DIR; pwd)
12+
REPO=${PROJECT}/$(basename $CODE_DIR);
13+
echo $REPO
14+
15+
TAG=$2
16+
if [[ -n "$CI" ]]; then
17+
TAG=$WERCKER_GIT_COMMIT
18+
fi
19+
20+
if [[ -z "$TAG" ]] ; then
21+
TAG=latest
22+
fi
23+
24+
if [[ "$(uname)" == "Darwin" ]]; then
25+
DOCKER_CMD=docker
26+
else
27+
DOCKER_CMD="sudo docker"
28+
fi
29+
30+
cd $CODE_DIR
31+
echo "Building $REPO:$TAG ..."
32+
$DOCKER_CMD build -t ${REPO}:${TAG} .

ci/push.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
4+
# The Universal Permissive License (UPL), Version 1.0
5+
#
6+
7+
# set -ev
8+
9+
if [[ -z "$OCIR" ]] ; then
10+
echo "Cannot find OCIR env var"
11+
exit 1
12+
fi
13+
14+
PROJECT="mushop"
15+
SRC_DIR=$1
16+
CONTAINER=$(basename $SRC_DIR);
17+
18+
push() {
19+
DOCKER_PUSH=1;
20+
while [ $DOCKER_PUSH -gt 0 ] ; do
21+
echo "Pushing $1";
22+
docker push $1;
23+
DOCKER_PUSH=$(echo $?);
24+
if [[ "$DOCKER_PUSH" -gt 0 ]] ; then
25+
echo "Docker push failed with exit code $DOCKER_PUSH";
26+
fi;
27+
done;
28+
}
29+
30+
tag_and_push() {
31+
SEMREG='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)'
32+
if [[ -z "$1" ]] ; then
33+
echo "Please pass the tag"
34+
exit 1
35+
else
36+
SEM=`echo $1 | sed -e "s#^v##"`
37+
TAGS=$SEM
38+
MAJOR=`echo $SEM | sed -e "s#$SEMREG#\1#"`
39+
MINOR=`echo $SEM | sed -e "s#$SEMREG#\2#"`
40+
PATCH=`echo $SEM | sed -e "s#$SEMREG#\3#"`
41+
SPECIAL=`echo $SEM | sed -e "s#$SEMREG#\4#"`
42+
# add semantic tags
43+
if [ "$MAJOR" != "$SEM" ] && [ -z "$SPECIAL" ]; then
44+
TAGS="$SEM $MAJOR.$MINOR $MAJOR latest"
45+
if [ -n "$SPECIAL" ]; then
46+
TAGS="$MAJOR.$MINOR.$PATCH $TAGS"
47+
fi
48+
fi
49+
fi
50+
51+
DOCKER_REPO=${PROJECT}/${CONTAINER}
52+
OCIR_REPO=${OCIR}/ateam/${PROJECT}-${CONTAINER}
53+
54+
# determine src tag
55+
SRC="${DOCKER_REPO}:latest"
56+
if [[ -n "$CI" ]]; then
57+
SRC="${DOCKER_REPO}:${WERCKER_GIT_COMMIT}"
58+
fi
59+
60+
for tag in $TAGS; do
61+
echo "Tagging ${OCIR_REPO}:$tag"
62+
docker tag $SRC ${OCIR_REPO}:$tag
63+
push "$OCIR_REPO:$tag";
64+
done
65+
}
66+
67+
# when running in Wercker CI
68+
if [ -n "$CI" ]; then
69+
# Push snapshot when in master
70+
if [ "$WERCKER_GIT_BRANCH" == "master" ] && [ -z "$WERCKER_PULL_REQUEST" ]; then
71+
tag_and_push master-${WERCKER_GIT_COMMIT:0:8}
72+
fi;
73+
74+
# Push tag and latest when tagged
75+
if [ -n "$GIT_TAG" ]; then
76+
tag_and_push ${GIT_TAG}
77+
fi;
78+
# Running manually
79+
elif [ -n "$2" ]; then
80+
echo "Pushing tag $2"
81+
tag_and_push $2
82+
else
83+
echo "Error: Unknown tag for push"
84+
exit 1
85+
fi;

ci/tag_and_push.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Script generates a space-delimited list of Docker image tags, based on the
2+
# provided version, pulls the temporary image (tagged with WERCKER_GIT_COMMIT)
3+
# and pushes all images with different tags.
4+
5+
# For example:
6+
# $ ./tag_and_push.sh 1.2.3
7+
# Pushes images with tags: 1.2.3 1.2 1 latest
8+
9+
# If run on a master branch:
10+
# $ ./tag_and_push.sh 1.2.3
11+
# Pushes images with tags: 1.2.3 1.2 1 latest master-SHA
12+
13+
OCIR=phx.ocir.io
14+
TEMP_IMAGE=$DOCKER_REPOSITORY/$SERVICE_NAME:$WERCKER_GIT_COMMIT
15+
16+
VERSION=$1
17+
if [[ -z "$VERSION" ]] ; then
18+
echo "Provide the version (e.g. 1.2.3)"
19+
exit 1
20+
fi
21+
22+
login() {
23+
echo -e "\nLogin ${DOCKER_USERNAME} to ${OCIR}"
24+
EXIT_CODE=$(docker login --username $DOCKER_USERNAME --password $DOCKER_PASSWORD $OCIR)
25+
if [[ "$EXIT_CODE" -gt 0 ]] ; then
26+
echo "Failed to login to Docker"
27+
exit 1
28+
fi
29+
}
30+
31+
pull_temp_image() {
32+
echo -e "\nPulling base image: ${TEMP_IMAGE}"
33+
EXIT_CODE=$(docker pull $TEMP_IMAGE)
34+
if [[ "$EXIT_CODE" -gt 0 ]] ; then
35+
echo "Failed to pull temp image"
36+
exit 1
37+
fi
38+
}
39+
40+
create_tags() {
41+
SEMREG='[^0-9]*\([0-9]*\)[.]\([0-9]*\)[.]\([0-9]*\)\([0-9A-Za-z-]*\)'
42+
SEM=`echo $1 | sed -e "s#^v##"`
43+
TAGS=$SEM
44+
MAJOR=`echo $SEM | sed -e "s#$SEMREG#\1#"`
45+
MINOR=`echo $SEM | sed -e "s#$SEMREG#\2#"`
46+
PATCH=`echo $SEM | sed -e "s#$SEMREG#\3#"`
47+
SPECIAL=`echo $SEM | sed -e "s#$SEMREG#\4#"`
48+
# add semantic tags
49+
if [ "$MAJOR" != "$SEM" ] && [ -z "$SPECIAL" ]; then
50+
TAGS="$SEM $MAJOR.$MINOR $MAJOR latest"
51+
if [ -n "$SPECIAL" ]; then
52+
TAGS="$MAJOR.$MINOR.$PATCH $TAGS"
53+
fi
54+
fi
55+
56+
login
57+
pull_temp_image
58+
59+
echo -e "\nPushing tags: ${TAGS}"
60+
for tag in $TAGS; do
61+
echo -e "\nTagging: ${DOCKER_REPOSITORY}/${SERVICE_NAME}:${tag}"
62+
EXIT_CODE=$(docker tag $TEMP_IMAGE $DOCKER_REPOSITORY/$SERVICE_NAME:$tag)
63+
if [[ "$EXIT_CODE" -gt 0 ]] ; then
64+
echo "Failed to tag image"
65+
exit 1
66+
fi
67+
68+
echo -e "\nPushing: ${DOCKER_REPOSITORY}/${SERVICE_NAME}:${tag}"
69+
EXIT_CODE=$(docker push $DOCKER_REPOSITORY/$SERVICE_NAME:$tag)
70+
if [[ "$EXIT_CODE" -gt 0 ]] ; then
71+
echo "Failed to push image"
72+
exit 1
73+
fi
74+
done
75+
}
76+
77+
BRANCH_TAGS=""
78+
VERSION_TAGS=$(create_tags $VERSION)
79+
80+
# If we are running on a master branch, we also need the
81+
# branch tag (e.g. 'master-SHA').
82+
if [ "$WERCKER_GIT_BRANCH" == "master" ] ; then
83+
BRANCH_TAGS=$(create_tags ${WERCKER_GIT_BRANCH}-${WERCKER_GIT_COMMIT:0:8})
84+
echo $VERSION_TAGS $BRANCH_TAGS
85+
else
86+
echo $VERSION_TAGS
87+
fi

deploy/basic/terraform/atp.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
# creates an ATP database
66
resource "oci_database_autonomous_database" "mushop_autonomous_database" {
77
#Required
8-
admin_password = "${random_string.autonomous_database_wallet_password.result}"
9-
compartment_id = "${var.compartment_ocid}"
8+
admin_password = random_string.autonomous_database_wallet_password.result
9+
compartment_id = var.compartment_ocid
1010
cpu_core_count = 1
1111
data_storage_size_in_tbs = 1
1212
db_name = "${var.database_name}${random_id.mushop_id.dec}"
13-
freeform_tags = "${local.common_tags}"
13+
freeform_tags = local.common_tags
1414
is_free_tier = true
1515

1616
#Optional

deploy/basic/terraform/datasources.tf

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
# Gets a list of Availability Domains
66
data "oci_identity_availability_domains" "ADs" {
77

8-
compartment_id = "${var.tenancy_ocid}"
8+
compartment_id = var.tenancy_ocid
99

1010
}
1111

1212

1313
data "oci_objectstorage_namespace" "user_namespace" {
1414

15-
compartment_id = "${var.compartment_ocid}"
15+
compartment_id = var.compartment_ocid
1616

1717
}
1818

@@ -35,8 +35,28 @@ resource "random_id" "mushop_id" {
3535

3636
data "oci_database_autonomous_database_wallet" "autonomous_database_wallet" {
3737

38-
autonomous_database_id = "${oci_database_autonomous_database.mushop_autonomous_database.id}"
39-
password = "${random_string.autonomous_database_wallet_password.result}"
40-
base64_encode_content = "false"
38+
autonomous_database_id = oci_database_autonomous_database.mushop_autonomous_database.id
39+
password = random_string.autonomous_database_wallet_password.result
40+
base64_encode_content = "true"
4141

4242
}
43+
44+
data "oci_limits_services" "test_services" {
45+
#Required
46+
compartment_id = var.tenancy_ocid
47+
48+
filter {
49+
name = "name"
50+
values = ["compute"]
51+
}
52+
}
53+
54+
data "oci_limits_limit_values" "test_limit_values" {
55+
count = length(data.oci_identity_availability_domains.ADs.availability_domains)
56+
compartment_id = var.tenancy_ocid
57+
service_name = data.oci_limits_services.test_services.services.0.name
58+
59+
availability_domain = data.oci_identity_availability_domains.ADs.availability_domains[count.index].name
60+
name = "vm-standard-e2-1-micro-count"
61+
scope_type = "AD"
62+
}

deploy/basic/terraform/loadbalancer.tf

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
resource "oci_load_balancer_load_balancer" "mushop_lb" {
22

3-
compartment_id = "${var.compartment_ocid}"
3+
compartment_id = var.compartment_ocid
44
display_name = "mushop-${random_id.mushop_id.dec}"
5-
shape = "${local.lb_shape}"
6-
subnet_ids = ["${oci_core_subnet.mushopLBSubnet.id}"]
5+
shape = local.lb_shape
6+
subnet_ids = [oci_core_subnet.mushopLBSubnet.id]
77
is_private = "false"
8-
freeform_tags = "${local.common_tags}"
8+
freeform_tags = local.common_tags
99

1010
}
1111

1212
resource "oci_load_balancer_backend_set" "mushop-bes" {
1313
name = "mushop-${random_id.mushop_id.dec}"
14-
load_balancer_id = "${oci_load_balancer_load_balancer.mushop_lb.id}"
14+
load_balancer_id = oci_load_balancer_load_balancer.mushop_lb.id
1515
policy = "IP_HASH"
1616

1717
health_checker {
@@ -27,10 +27,10 @@ resource "oci_load_balancer_backend_set" "mushop-bes" {
2727
}
2828

2929
resource "oci_load_balancer_backend" "mushop-be" {
30-
count = "${var.num_nodes}"
31-
load_balancer_id = "${oci_load_balancer_load_balancer.mushop_lb.id}"
32-
backendset_name = "${oci_load_balancer_backend_set.mushop-bes.name}"
33-
ip_address = "${element(oci_core_instance.app-instance.*.private_ip, count.index)}"
30+
count = var.num_nodes
31+
load_balancer_id = oci_load_balancer_load_balancer.mushop_lb.id
32+
backendset_name = oci_load_balancer_backend_set.mushop-bes.name
33+
ip_address = element(oci_core_instance.app-instance.*.private_ip, count.index)
3434
port = 80
3535
backup = false
3636
drain = false
@@ -41,8 +41,8 @@ resource "oci_load_balancer_backend" "mushop-be" {
4141
resource "oci_load_balancer_listener" "mushop_listener" {
4242
#Required
4343

44-
load_balancer_id = "${oci_load_balancer_load_balancer.mushop_lb.id}"
45-
default_backend_set_name = "${oci_load_balancer_backend_set.mushop-bes.name}"
44+
load_balancer_id = oci_load_balancer_load_balancer.mushop_lb.id
45+
default_backend_set_name = oci_load_balancer_backend_set.mushop-bes.name
4646
name = "mushop-${random_id.mushop_id.dec}"
4747
port = 80
4848
protocol = "HTTP"

0 commit comments

Comments
 (0)