utilize ENV for most endpoint hostnames
This commit is contained in:
@@ -14,6 +14,9 @@ const express = require('express');
|
||||
|
||||
var redisConnected = false;
|
||||
|
||||
var redisHost = process.env.REDIS_HOST || 'redis'
|
||||
var catalogueHost = process.env.CATALOGUE_HOST || 'catalogue'
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use((req, res, next) => {
|
||||
@@ -284,7 +287,7 @@ function calcTax(total) {
|
||||
|
||||
function getProduct(sku) {
|
||||
return new Promise((resolve, reject) => {
|
||||
request('http://catalogue:8080/product/' + sku, (err, res, body) => {
|
||||
request('http://' + catalogueHost + ':8080/product/' + sku, (err, res, body) => {
|
||||
if(err) {
|
||||
reject(err);
|
||||
} else if(res.statusCode != 200) {
|
||||
@@ -308,7 +311,7 @@ function saveCart(id, cart) {
|
||||
|
||||
// connect to Redis
|
||||
var redisClient = redis.createClient({
|
||||
host: 'redis'
|
||||
host: redisHost
|
||||
});
|
||||
|
||||
redisClient.on('error', (e) => {
|
||||
|
@@ -3,9 +3,11 @@ FROM golang:1.9.2
|
||||
WORKDIR /opt/gorcv
|
||||
|
||||
ENV GOPATH=/opt/gorcv \
|
||||
GOBIN=/opt/gorcv/bin
|
||||
GOBIN=/opt/gorcv/bin \
|
||||
AMQP_URI=rabbitmq
|
||||
|
||||
# install external components
|
||||
# @todo godep
|
||||
RUN go get \
|
||||
github.com/streadway/amqp \
|
||||
github.com/instana/golang-sensor
|
||||
@@ -14,5 +16,7 @@ COPY src /opt/gorcv/
|
||||
|
||||
RUN go build && go install
|
||||
|
||||
# @todo stage this build
|
||||
|
||||
CMD bin/gorcv
|
||||
|
||||
|
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
"os"
|
||||
|
||||
"github.com/streadway/amqp"
|
||||
"github.com/instana/golang-sensor"
|
||||
@@ -15,9 +16,8 @@ const (
|
||||
Service = "Dispatch"
|
||||
)
|
||||
|
||||
var amqpUri string = "amqp://guest:guest@rabbitmq:5672/"
|
||||
|
||||
var (
|
||||
amqpUri string
|
||||
rabbitChan *amqp.Channel
|
||||
rabbitCloseError chan *amqp.Error
|
||||
rabbitReady chan bool
|
||||
@@ -111,6 +111,9 @@ func main() {
|
||||
Service: Service,
|
||||
LogLevel: instana.Info}))
|
||||
|
||||
// Init amqpUri
|
||||
amqpUri = fmt.Sprintf("amqp://guest:guest@%s:5672/", os.Getenv("AMQP_HOST"))
|
||||
|
||||
// MQ error channel
|
||||
rabbitCloseError = make(chan *amqp.Error)
|
||||
|
||||
|
@@ -1,8 +1,9 @@
|
||||
import json
|
||||
import pika
|
||||
import os
|
||||
|
||||
class Publisher:
|
||||
HOST = 'rabbitmq'
|
||||
HOST = os.getenv("AMQP_HOST", "rabbitmq")
|
||||
VIRTUAL_HOST = '/'
|
||||
EXCHANGE='robot-shop'
|
||||
TYPE='direct'
|
||||
|
@@ -22,6 +22,9 @@ EXPOSE 8080
|
||||
|
||||
WORKDIR /opt/shipping
|
||||
|
||||
ENV CART_ENDPOINT=cart:8080
|
||||
ENV DB_HOST=mysql
|
||||
|
||||
COPY --from=build /opt/shipping/target/shipping-1.0-jar-with-dependencies.jar shipping.jar
|
||||
|
||||
CMD [ "java", "-jar", "shipping.jar" ]
|
||||
|
@@ -30,11 +30,17 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Main {
|
||||
private static String CART_URL = "http://cart:8080/shipping/";
|
||||
private static String CART_URL = null;
|
||||
private static String JDBC_URL = null;
|
||||
private static Logger logger = LoggerFactory.getLogger(Main.class);
|
||||
private static ComboPooledDataSource cpds = null;
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Get ENV configuration values
|
||||
Map<String, String> env = System.getenv();
|
||||
CART_URL = String.format("http://%s/shipping/", env.get("CART_ENDPOINT"));
|
||||
JDBC_URL = String.format("jdbc:mysql://%s/cities?useSSL=false&autoReconnect=true", env.get("DB_HOST"));
|
||||
|
||||
//
|
||||
// Create database connector
|
||||
// TODO - might need a retry loop here
|
||||
@@ -42,7 +48,7 @@ public class Main {
|
||||
try {
|
||||
cpds = new ComboPooledDataSource();
|
||||
cpds.setDriverClass( "com.mysql.jdbc.Driver" ); //loads the jdbc driver
|
||||
cpds.setJdbcUrl( "jdbc:mysql://mysql/cities?useSSL=false&autoReconnect=true" );
|
||||
cpds.setJdbcUrl( JDBC_URL );
|
||||
cpds.setUser("shipping");
|
||||
cpds.setPassword("secret");
|
||||
// some config
|
||||
|
@@ -196,7 +196,7 @@ app.get('/history/:id', (req, res) => {
|
||||
|
||||
// connect to Redis
|
||||
var redisClient = redis.createClient({
|
||||
host: 'redis'
|
||||
host: process.env.REDIS_HOST || 'redis'
|
||||
});
|
||||
|
||||
redisClient.on('error', (e) => {
|
||||
|
@@ -2,9 +2,15 @@ FROM nginx:1.13.8
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
ENV CATALOGUE_HOST=catalogue \
|
||||
USER_HOST=user \
|
||||
CART_HOST=cart \
|
||||
SHIPPING_HOST=shipping \
|
||||
PAYMENT_HOST=payment
|
||||
|
||||
COPY entrypoint.sh /root/
|
||||
ENTRYPOINT ["/root/entrypoint.sh"]
|
||||
|
||||
COPY default.conf /etc/nginx/conf.d/default.conf
|
||||
COPY default.conf.template /etc/nginx/conf.d/default.conf.template
|
||||
COPY static /usr/share/nginx/html
|
||||
|
||||
|
@@ -44,23 +44,23 @@ server {
|
||||
#}
|
||||
|
||||
location /api/catalogue/ {
|
||||
proxy_pass http://catalogue:8080/;
|
||||
proxy_pass http://${CATALOGUE_HOST}:8080/;
|
||||
}
|
||||
|
||||
location /api/user/ {
|
||||
proxy_pass http://user:8080/;
|
||||
proxy_pass http://${USER_HOST}:8080/;
|
||||
}
|
||||
|
||||
location /api/cart/ {
|
||||
proxy_pass http://cart:8080/;
|
||||
proxy_pass http://${CART_HOST}:8080/;
|
||||
}
|
||||
|
||||
location /api/shipping/ {
|
||||
proxy_pass http://shipping:8080/;
|
||||
proxy_pass http://${SHIPPING_HOST}:8080/;
|
||||
}
|
||||
|
||||
location /api/payment/ {
|
||||
proxy_pass http://payment:8080/;
|
||||
proxy_pass http://${PAYMENT_HOST}:8080/;
|
||||
}
|
||||
|
||||
location /nginx_status {
|
@@ -32,5 +32,8 @@ fi
|
||||
# make sure nginx can access the eum file
|
||||
chmod 644 $BASE_DIR/eum.html
|
||||
|
||||
# apply environment variables to default.conf
|
||||
envsubst < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf
|
||||
|
||||
exec nginx -g "daemon off;"
|
||||
|
||||
|
Reference in New Issue
Block a user