Skip to content

Commit 275cd52

Browse files
committed
introduce docker
1 parent 63176cc commit 275cd52

11 files changed

+133
-34
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ language: node_js
44
cache: yarn
55
node_js:
66
- '7.1.0'
7+
services:
8+
- docker
79

810
before_install:
911
- export CHROME_BIN=chromium-browser

codedeploy/application_start.sh

-8
This file was deleted.

codedeploy/appspec.yml

-7
This file was deleted.

config/webpack.aot.js

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const webpack = require('webpack');
33
const webpackMerge = require('webpack-merge');
44
const commonConfig = require('./webpack.common.js');
55

6+
const ManifestPlugin = require('webpack-manifest-plugin');
7+
68
const ENV = process.env.NODE_ENV = process.env.ENV = 'production';
79
const PUBLIC_PATH = (process.env.PUBLIC_PATH || '') + '/' ;
810

@@ -44,6 +46,7 @@ module.exports = webpackMerge(commonConfig, {
4446
comments: false,
4547
sourceMap: true
4648
}),
49+
new ManifestPlugin(),
4750
],
4851
node: {
4952
global: true,

docker/Dockerfile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM nginx:alpine
2+
3+
ENV BUILD_PACKAGES .build-dependencies curl-dev ruby-dev build-base
4+
ENV RUBY_PACKAGES ruby ruby-json
5+
6+
RUN apk update && \
7+
apk upgrade && \
8+
apk add --no-cache --virtual $BUILD_PACKAGES && \
9+
apk add --no-cache $RUBY_PACKAGES && \
10+
apk del .build-dependencies
11+
12+
ADD ../dist /usr/share/nginx/html
13+
14+
WORKDIR /tmp
15+
16+
COPY index.html.erb .
17+
COPY render_template.rb .
18+
COPY ../dist/manifest.json .
19+
20+
CMD ruby render_template.rb > /usr/share/nginx/html/index.html && \
21+
nginx -g 'daemon off;'
22+

docker/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```bash
2+
docker run -p 8000:80 -e "ASSET_URL=//your.cdn.host" IMAGE
3+
```

docker/index.html.erb

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="x-ua-compatible" content="ie=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<title>Spring Boot and Angular2 tutorial</title>
8+
<base href="/" />
9+
<style type="text/css">
10+
body {
11+
padding-top: 5rem;
12+
}
13+
</style>
14+
<link href="<%= "#{ENV['ASSET_URL']}/#{@data['vendor.css']}" %>" rel="stylesheet"></head>
15+
<body>
16+
17+
<mpt-app>test</mpt-app>
18+
19+
<!-- Google Analytics: change UA-74585747-1 to be your site's ID -->
20+
<script>
21+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
22+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
23+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
24+
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
25+
26+
ga('create', 'UA-74585747-1', 'auto');
27+
ga('send', 'pageview');
28+
</script>
29+
<script type="text/javascript" src="<%= "#{ENV['ASSET_URL']}/#{@data['polyfills.js']}" %>"></script>
30+
<script type="text/javascript" src="<%= "#{ENV['ASSET_URL']}/#{@data['vendor.js']}" %>"></script>
31+
<script type="text/javascript" src="<%= "#{ENV['ASSET_URL']}/#{@data['main.js']}" %>"></script>
32+
</body>
33+
</html>

docker/render_template.rb

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require "erb"
2+
require "json"
3+
4+
class Renderer
5+
include ERB::Util
6+
7+
def initialize(data, template)
8+
@data = data
9+
@template = template
10+
end
11+
12+
def render
13+
ERB.new(@template).result(binding)
14+
end
15+
end
16+
17+
data = JSON.parse(File.read(File.join(File.dirname(__FILE__), 'manifest.json')))
18+
template = File.read(File.join(File.dirname(__FILE__), 'index.html.erb'))
19+
20+
r = Renderer.new(data, template)
21+
puts r.render

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
"typescript": "~2.0.10",
8989
"webpack": ">=2.1.0-beta.27",
9090
"webpack-dev-server": ">=2.1.0-beta.11",
91+
"webpack-manifest-plugin": "^1.1.0",
9192
"webpack-merge": "^1.0.2"
9293
}
9394
}

scripts/deploy.sh

+13-13
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ if [ ! -v AWS_SESSION_TOKEN ]; then
66
source ./scripts/switch-role.sh
77
fi
88

9-
# set variables
10-
CDN_URL="https://cdn-${ENV}.hana053.com"
11-
S3_CDN_URL="s3://cdn-${ENV}.hana053.com"
129

13-
# build
14-
PUBLIC_PATH=${CDN_URL} yarn run build
10+
yarn run build
1511

16-
# create codedeploy archive
17-
tar czvf dist/codedeploy.tgz -C codedeploy .
12+
(
13+
cd docker
1814

19-
# deploy
20-
aws s3 sync --delete --acl public-read dist ${S3_CDN_URL}
15+
readonly DOCKER_NAME=micropost/frontend
16+
readonly AWS_ACCOUNT_NUMBER=$(aws sts get-caller-identity --output text --query 'Account')
2117

22-
# invalidate cached index.html by using codedeploy
23-
aws deploy create-deployment --application-name micropost \
24-
--s3-location bucket=cdn-${ENV}.hana053.com,key=codedeploy.tgz,bundleType=tgz \
25-
--deployment-group-name web-frontend
18+
eval $(aws ecr get-login)
19+
docker build -t ${DOCKER_NAME} .
20+
docker tag ${DOCKER_NAME}:latest ${AWS_ACCOUNT_NUMBER}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${DOCKER_NAME}:latest
21+
docker push ${AWS_ACCOUNT_NUMBER}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${DOCKER_NAME}:latest
22+
)
23+
24+
#aws sns publish --topic-arn "arn:aws:sns:${AWS_DEFAULT_REGION}:${AWS_ACCOUNT_NUMBER}:backend_app_updated" \
25+
# --message "${ENV}: ${TRAVIS_COMMIT}"

yarn.lock

+35-6
Original file line numberDiff line numberDiff line change
@@ -1533,6 +1533,16 @@ fs-access@^1.0.0:
15331533
dependencies:
15341534
null-check "^1.0.0"
15351535

1536+
fs-extra@^0.30.0:
1537+
version "0.30.0"
1538+
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-0.30.0.tgz#f233ffcc08d4da7d432daa449776989db1df93f0"
1539+
dependencies:
1540+
graceful-fs "^4.1.2"
1541+
jsonfile "^2.1.0"
1542+
klaw "^1.0.0"
1543+
path-is-absolute "^1.0.0"
1544+
rimraf "^2.2.8"
1545+
15361546
fs.realpath@^1.0.0:
15371547
version "1.0.0"
15381548
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
@@ -1643,7 +1653,7 @@ glogg@^1.0.0:
16431653
dependencies:
16441654
sparkles "^1.0.0"
16451655

1646-
graceful-fs@^4.1.2:
1656+
graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9:
16471657
version "4.1.11"
16481658
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
16491659

@@ -2169,6 +2179,12 @@ json5@^0.5.0:
21692179
version "0.5.1"
21702180
resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821"
21712181

2182+
jsonfile@^2.1.0:
2183+
version "2.4.0"
2184+
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-2.4.0.tgz#3736a2b428b87bbda0cc83b53fa3d633a35c2ae8"
2185+
optionalDependencies:
2186+
graceful-fs "^4.1.6"
2187+
21722188
jsonify@~0.0.0:
21732189
version "0.0.0"
21742190
resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73"
@@ -2281,6 +2297,12 @@ kind-of@^3.0.2:
22812297
dependencies:
22822298
is-buffer "^1.0.2"
22832299

2300+
klaw@^1.0.0:
2301+
version "1.3.1"
2302+
resolved "https://registry.yarnpkg.com/klaw/-/klaw-1.3.1.tgz#4088433b46b3b1ba259d78785d8e96f73ba02439"
2303+
optionalDependencies:
2304+
graceful-fs "^4.1.9"
2305+
22842306
lazy-cache@^1.0.3:
22852307
version "1.0.4"
22862308
resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-1.0.4.tgz#a1d78fc3a50474cb80845d3b3b6e1da49a446e8e"
@@ -2493,14 +2515,14 @@ lodash.unionwith@^4.6.0:
24932515
version "4.6.0"
24942516
resolved "https://registry.yarnpkg.com/lodash.unionwith/-/lodash.unionwith-4.6.0.tgz#74d140b5ca8146e6c643c3724f5152538d9ac1f0"
24952517

2518+
"lodash@>=3.5 <5", lodash@^4.13.1, lodash@^4.14.0, lodash@^4.16.2, lodash@^4.16.4, lodash@^4.3.0, lodash@^4.5.0:
2519+
version "4.17.2"
2520+
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.2.tgz#34a3055babe04ce42467b607d700072c7ff6bf42"
2521+
24962522
lodash@^3.8.0:
24972523
version "3.10.1"
24982524
resolved "https://registry.yarnpkg.com/lodash/-/lodash-3.10.1.tgz#5bf45e8e49ba4189e17d482789dfd15bd140b7b6"
24992525

2500-
lodash@^4.13.1, lodash@^4.14.0, lodash@^4.16.2, lodash@^4.16.4, lodash@^4.3.0, lodash@^4.5.0:
2501-
version "4.17.2"
2502-
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.2.tgz#34a3055babe04ce42467b607d700072c7ff6bf42"
2503-
25042526
log-driver@1.2.5:
25052527
version "1.2.5"
25062528
resolved "https://registry.yarnpkg.com/log-driver/-/log-driver-1.2.5.tgz#7ae4ec257302fd790d557cb10c97100d857b0056"
@@ -3662,7 +3684,7 @@ right-align@^0.1.1:
36623684
dependencies:
36633685
align-text "^0.1.1"
36643686

3665-
rimraf@2, rimraf@^2.3.3, rimraf@^2.4.4, rimraf@^2.5.4, rimraf@~2.5.1, rimraf@~2.5.4:
3687+
rimraf@2, rimraf@^2.2.8, rimraf@^2.3.3, rimraf@^2.4.4, rimraf@^2.5.4, rimraf@~2.5.1, rimraf@~2.5.4:
36663688
version "2.5.4"
36673689
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.5.4.tgz#96800093cbf1a0c86bd95b4625467535c29dfa04"
36683690
dependencies:
@@ -4390,6 +4412,13 @@ webpack-dev-server@>=2.1.0-beta.11:
43904412
webpack-dev-middleware "^1.4.0"
43914413
yargs "^6.0.0"
43924414

4415+
webpack-manifest-plugin@^1.1.0:
4416+
version "1.1.0"
4417+
resolved "https://registry.yarnpkg.com/webpack-manifest-plugin/-/webpack-manifest-plugin-1.1.0.tgz#6b6c718aade8a2537995784b46bd2e9836057caa"
4418+
dependencies:
4419+
fs-extra "^0.30.0"
4420+
lodash ">=3.5 <5"
4421+
43934422
webpack-merge@^1.0.2:
43944423
version "1.0.2"
43954424
resolved "https://registry.yarnpkg.com/webpack-merge/-/webpack-merge-1.0.2.tgz#b28f4c895361f1a985a96952760d7170679779b4"

0 commit comments

Comments
 (0)