Skip to content

Commit

Permalink
Merge pull request #15 from oracle/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
junior authored Sep 17, 2019
2 parents f4013cc + 5500c16 commit df92028
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 31 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ that creates all the required resources and configures the application on the cr

The steps below guide you through deploying the application on your tenancy using the OCI Resource Manager.

1. Download the latest [`mushop-v1.0.0-basic-stack.zip`](../../releases/download/v1.0.0/mushop-v1.0.0-basic-stack.zip) file.
2. [Login](https://console.us-phoenix-1.oraclecloud.com/resourcemanager/stacks/create) to Oracle Cloud Infrastructure to import the stack
1. Download the latest [`mushop-basic-stack-v1.0.1.zip`](../../releases/download/v1.0.1/mushop-basic-stack-v1.0.1.zip) file.
2. [Login](https://console.us-ashburn-1.oraclecloud.com/resourcemanager/stacks/create) to Oracle Cloud Infrastructure to import the stack
> `Home > Solutions & Platform > Resource Manager > Stacks > Create Stack`
3. Upload the `mushop-v1.0.0-basic-stack.zip` file that was downloaded earlier, and provide a name and description for the stack
3. Upload the `mushop-basic-stack-v1.0.1.zip` file that was downloaded earlier, and provide a name and description for the stack
4. Configure the stack
1. **Database Name** - You can choose to provide a database name (optional)
2. **Node Count** - Select if you want to deploy one or two application instances.
Expand Down
2 changes: 1 addition & 1 deletion deploy/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The application uses a typical topology for a 3-tier web application as follows

- Generate Stack Zip Package for OCI Resource Manager

`docker run -v $PWD:/transfer --rm --entrypoint cp mushop-basic:latest /package/mushop-basic.zip /transfer/mushop-basic-stack.zip`
`docker run -v $PWD:/transfer --rm --entrypoint cp mushop-basic:latest /package/mushop-basic-stack.zip /transfer/mushop-basic-stack.zip`

This creates a `.zip` file in your working directory that can be imported in to OCI Resource Manager.

Expand Down
4 changes: 2 additions & 2 deletions deploy/basic/terraform/loadbalancer.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ resource "oci_load_balancer_backend_set" "mushop-bes" {
port = "80"
protocol = "HTTP"
response_body_regex = ".*"
url_path = "/"
url_path = "/api/health"
return_code = 200
interval_ms = 10000
interval_ms = 5000
timeout_in_millis = 2000
retries = 10
}
Expand Down
46 changes: 34 additions & 12 deletions deploy/basic/terraform/scripts/node.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
#!/bin/bash
# Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
#
#
#
# Description: Sets up Mushop "Monolite".
# Return codes: 0 =
# Return codes: 0 =
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
#
#

get_object() {
out_file=$1
os_uri=$2
success=1
for i in $(seq 1 9); do
echo "trying ($i) $2"
http_status=$(curl -w '%%{http_code}' -L -s -o $1 $2)
if [ "$http_status" -eq "200" ]; then
success=0
echo "saved to $1"
break
else
sleep 15
fi
done
return $success
}

# Configure firewall
firewall-offline-cmd --add-port=80/tcp
Expand Down Expand Up @@ -34,24 +52,28 @@ MUSHOP_APP_URI=$(curl -L http://169.254.169.254/opc/v1/instance/metadata | jq -j
WALLET_URI=$(curl -L http://169.254.169.254/opc/v1/instance/metadata | jq -j ".wallet_par")

# get artifacts from object storage
wget -O /root/wallet.zip $${WALLET_URI}
wget -O /root/catalogue.sql $${CATALOGUE_SQL_URI}
wget -O /etc/httpd/conf/httpd.conf $${APACHE_CONF_URI}
wget -O /root/entrypoint.sh $${ENTRYPOINT_URI}

get_object /root/wallet.zip $${WALLET_URI}
# Setup ATP wallet files
unzip /root/wallet.zip -d /usr/lib/oracle/19.3/client64/lib/network/admin/

# Init DB
get_object /root/catalogue.sql $${CATALOGUE_SQL_URI}
sqlplus admin/$${ATP_PW}@$${ATP_DB_NAME}_tp @/root/catalogue.sql

export OADB_USER=catalogue_user
export OADB_PW=default_Password1
export OADB_SERVICE=$${ATP_DB_NAME}_tp
# Get http server config
get_object /etc/httpd/conf/httpd.conf $${APACHE_CONF_URI}

wget -O /root/mushop-bin.tar.gz $${MUSHOP_APP_URI}
#Get binaries
get_object /root/mushop-bin.tar.gz $${MUSHOP_APP_URI}
tar zxvf /root/mushop-bin.tar.gz -C /

# setup init script
get_object /root/entrypoint.sh $${ENTRYPOINT_URI}
chmod +x /root/entrypoint.sh

# Setup app variables
export OADB_USER=catalogue_user
export OADB_PW=default_Password1
export OADB_SERVICE=$${ATP_DB_NAME}_tp
cd /root
/root/entrypoint.sh >/root/mushop.log 2>&1 &
12 changes: 12 additions & 0 deletions deploy/basic/terraform/storage.tf
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,16 @@ resource "oci_objectstorage_preauthrequest" "mushop_lite_preauth" {
object = "${oci_objectstorage_object.mushop_basic.object}"
}

resource "oci_objectstorage_object_lifecycle_policy" "mushop_deploy_assets_lifecycle_policy" {
namespace = "${data.oci_objectstorage_namespace.user_namespace.namespace}"
bucket = "${oci_objectstorage_bucket.mushop.name}"

rules {
action = "DELETE"
is_enabled = "true"
name = "mushop-delete-deploy-assets-rule"
time_amount = "1"
time_unit = "DAYS"

}
}
2 changes: 2 additions & 0 deletions src/catalogue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ To run it use:
./catalogue
```

Note: When doing development and running local, you need to set the variables to connect to the Oracle Autonomous Database. OADB_USER, OADB_PW and OADB_SERVICE need to be load as environment variables. Using [.env](https://docs.docker.com/compose/env-file/) file or EXPORT.

#### Docker
`docker-compose up`

Expand Down
2 changes: 1 addition & 1 deletion src/catalogue/cmd/cataloguesvc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func init() {

func main() {
var (
port = flag.String("port", getEnv("CATALOGUE_PORT", "80"), "Port to bind HTTP listener") // TODO(pb): should be -addr, default ":80"
port = flag.String("port", getEnv("CATALOGUE_PORT", "80"), "Port to bind HTTP listener")
images = flag.String("images", "./images/", "Image path")
connectString = flag.String("CONNECTSTRING", os.Getenv("OADB_USER")+"/"+os.Getenv("OADB_PW")+"@"+os.Getenv("OADB_SERVICE"), "Connection String: [username[/password]@][tnsname]]")
zip = flag.String("zipkin", os.Getenv("ZIPKIN"), "Zipkin address")
Expand Down
52 changes: 52 additions & 0 deletions src/catalogue/docker/docker-compose-zipkin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#
# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
#

version: '2'

services:
catalogue:
build:
context: ..
dockerfile: ./Dockerfile
image: mushop/catalogue
hostname: catalogue
restart: always
cap_drop:
- all
cap_add:
- NET_BIND_SERVICE
read_only: true
volumes:
- Wallet_Creds:/usr/lib/oracle/19.3/client64/lib/network/admin/
environment:
- reschedule=on-node-failure
- OADB_USER=${OADB_USER}
- OADB_PW=${OADB_PW}
- OADB_SERVICE=${OADB_SERVICE}
- ZIPKIN=http://zipkin:9411/api/v1/spans
ports:
- "8080:80"

zipkin:
image: openzipkin/zipkin
hostname: zipkin
restart: always
cap_drop:
- all
cap_add:
- CHOWN
- SETGID
- SETUID
read_only: true
tmpfs:
- /tmp:rw,noexec,nosuid
environment:
- reschedule=on-node-failure
ports:
- "9411:9411"

zipkinseed:
image: alpine
command: /bin/sh -c 'sleep 10 ; wget http://catalogue/health ; wget http://catalogue/catalogue ; wget http://catalogue/catalogue/size ; wget http://catalogue/categories'
6 changes: 3 additions & 3 deletions src/catalogue/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ services:
- Wallet_Creds:/usr/lib/oracle/19.3/client64/lib/network/admin/
environment:
- reschedule=on-node-failure
- OADB_USER=catalogue_user
- OADB_PW=default_Password1
- OADB_SERVICE=mcatalogue_tp
- OADB_USER=${OADB_USER}
- OADB_PW=${OADB_PW}
- OADB_SERVICE=${OADB_SERVICE}
ports:
- "8080:80"

9 changes: 0 additions & 9 deletions src/catalogue/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,3 @@ func cut(products []Product, pageNum, pageSize int) []Product {
}
return products[start:end]
}

func contains(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}

0 comments on commit df92028

Please sign in to comment.