Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
platylm committed Feb 27, 2020
2 parents 2290bb5 + 5196e89 commit aeba335
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Dockerfile.nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM nginx:1.16-alpine

COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf
2 changes: 2 additions & 0 deletions atdd/ui/shopping_cart_success.robot
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ ${notify} วันเวลาที่ชำระเงิน 1/3/2563 13
ตรวจสอบสรุปรายการสั่งซื้อ
ตรวจสอบตะกร้าสินค้า
ยืนยันคำสั่งซื้อ
ชำระค่าสินค้า
ได้รับการแจ้งเตือน

*** Keywords ***
ตรวจสอบข้อมูลสินค้า
Expand Down
13 changes: 13 additions & 0 deletions deploy/store-service-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: extentions/v1beta1
kind: Deployment
metadata:
name: store-service
spec:
replicas: 1
template:
metadata:
labels:
app: store-service
spec:
restartPolicy: Always

11 changes: 11 additions & 0 deletions deploy/store-service-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: store-service
spec:
selector:
app: store-service
port:
- protocal: TCP
port: 8000
targetPort: 8000
21 changes: 21 additions & 0 deletions deploy/store-web-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: store-web
labels:
app: store-web
spec:
replicas: 1
selector:
matchLabels:
app: store-web
template:
metadata:
labels:
app: store-web
spec:
containers:
- name: store-web
image: sckseal/shoppingcart-web:latest
ports:
- containerPort: 3000
25 changes: 24 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ version: "3.5"
services:
store-service:
image: toy-store-service:0.0.1
container_name: store-service
build:
context: store-service
ports:
Expand All @@ -13,6 +14,7 @@ services:

store-database:
image: mysql:5.7
container_name: store-database
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=sealteam
Expand All @@ -21,4 +23,25 @@ services:
volumes:
- ./tearup/:/docker-entrypoint-initdb.d/
ports:
- "3306:3306"
- "3306:3306"

store-ui:
image: toy-store-ui:0.0.1
container_name: store-ui
build:
context: store-web
ports:
- "3000:3000"

store-nginx:
image: toy-store-nginx:0.0.1
container_name: store-nginx
restart: always
build:
context: .
dockerfile: Dockerfile.nginx
depends_on:
- store-service
- store-ui
ports:
- "80:80"
56 changes: 56 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#https://steveholgado.com/nginx-for-nextjs/#nginx
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=STATIC:10m inactive=7d use_temp_path=off;

upstream store-service {
server store-service:8000;
}

upstream store-ui {
server store-ui:3000;
}

server {
listen 80 default_server;

server_name _;

server_tokens off;

gzip on;
gzip_proxied any;
gzip_comp_level 4;
gzip_types text/css application/javascript image/svg+xml;

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;

location /_next/static {
proxy_cache STATIC;
proxy_pass http://store-ui;

# For testing cache - remove before deploying to production
add_header X-Cache-Status $upstream_cache_status;
}

location /static {
proxy_cache STATIC;
proxy_ignore_headers Cache-Control;
proxy_cache_valid 60m;
proxy_pass http://store-ui;

# For testing cache - remove before deploying to production
add_header X-Cache-Status $upstream_cache_status;
}

location /api {
proxy_pass http://store-service;
}


location / {
proxy_pass http://store-ui;
}
}
2 changes: 1 addition & 1 deletion store-service/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func main() {
connection, err := sqlx.Connect("mysql", "sealteam:sckshuhari@(store-tearup:3306)/toy")
connection, err := sqlx.Connect("mysql", "sealteam:sckshuhari@(store-database:3306)/toy")
if err != nil {
log.Fatalln("cannot connect to tearup", err)
}
Expand Down
24 changes: 24 additions & 0 deletions store-web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion store-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
"author": "",
"license": "ISC",
"dependencies": {
"isomorphic-unfetch": "^3.0.0",
"jest-cli": "^25.1.0",
"next": "^9.2.2",
"react": "^16.13.0",
"react-dom": "^16.13.0"
"react-dom": "^16.13.0",
"swr": "^0.1.18"
},
"devDependencies": {
"eslint": "^6.8.0",
Expand Down
19 changes: 19 additions & 0 deletions store-web/pages/healthcheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

import fetch from 'isomorphic-unfetch'
import useSWR from 'swr'

const API_URL = '/api/v1/health'
async function fetcher() {
const res = await fetch(API_URL)
const json = await res.json()
return json
}

function HealthCheck(){
const { data, error } = useSWR('/repos/zeit/next.js', fetcher)
if (error) return <div>failed to load</div>
if (!data) return <div>loading...</div>
return <div>Next stars: {data.message.Name}</div>
}

export default HealthCheck

0 comments on commit aeba335

Please sign in to comment.