10 Commits
0.1.0 ... 0.3.0

14 changed files with 138 additions and 14 deletions

View File

@ -1,15 +1,32 @@
VERSION=`git describe --always`
VERSION:=$(shell git describe --always)
TARGET_ENV=prod
build: build-api build-web
build: dist/personal-measure-api.tar.gz dist/personal-measure-web.tar.gz
build-api:
dist/personal-measure-api.tar.gz:
-mkdir dist
make -C api personal_measure_api
tar czf dist/personal-measure-api-${VERSION}.tar.gz -C api personal_measure_api
cp dist/personal-measure-api-${VERSION}.tar.gz dist/personal-measure-api.tar.gz
build-web:
dist/personal-measure-web.tar.gz:
-mkdir dist
(cd web && npm run build)
tar czf dist/personal-measure-web-${VERSION}.tar.gz -C web/dist .
cp dist/personal-measure-web-${VERSION}.tar.gz dist/personal-measure-web.tar.gz
#deploy-api: build-api
deploy-api: dist/personal-measure-api.tar.gz
mkdir -p temp-deploy/personal-measure-api-${VERSION}
tar xzf dist/personal-measure-api-${VERSION}.tar.gz -C temp-deploy/personal-measure-api-${VERSION}
-ssh pmapi@pmapi.jdb-labs.com "sudo systemctl stop personal_measure_api.$(TARGET_ENV).service"
scp temp-deploy/personal-measure-api-${VERSION}/personal_measure_api pmapi@pmapi.jdb-labs.com:/home/pmapi/$(TARGET_ENV)/personal_measure_api
ssh pmapi@pmapi.jdb-labs.com "sudo systemctl start personal_measure_api.$(TARGET_ENV).service"
rm -r temp-deploy
deploy-web: dist/personal-measure-web.tar.gz
mkdir -p temp-deploy/personal-measure-web-${VERSION}
tar xzf dist/personal-measure-web-${VERSION}.tar.gz -C temp-deploy/personal-measure-web-${VERSION}
aws s3 sync temp-deploy/personal-measure-web-${VERSION} s3://pm.jdb-labs.com/$(TARGET_ENV)/webroot
rm -r temp-deploy
deploy: deploy-api deploy-web

View File

@ -35,7 +35,10 @@ template halt(code: HttpCode,
template jsonResp(code: HttpCode, details: string = "", headers: RawHeaders = @{:} ) =
halt(
code,
headers & @{"Content-Type": JSON},
headers & @{
"Content-Type": JSON,
"Cache-Control": "no-cache"
},
$(%* {
"statusCode": code.int,
"status": $code,

View File

@ -4,6 +4,8 @@ import json, macros, options, sequtils, strutils, times, timeutils, unicode,
const UNDERSCORE_RUNE = "_".toRunes[0]
const PG_TIMESTAMP_FORMATS = [
"yyyy-MM-dd HH:mm:sszz",
"yyyy-MM-dd HH:mm:ss'.'fzz",
"yyyy-MM-dd HH:mm:ss'.'ffzz",
"yyyy-MM-dd HH:mm:ss'.'fffzz"
]

View File

@ -1 +1 @@
const PM_API_VERSION* = "0.1.0"
const PM_API_VERSION* = "0.3.0"

View File

@ -7,3 +7,6 @@ User=pmapi
WorkingDirectory=/home/pmapi
ExecStart=/home/pmapi/personal_measure_api
Restart=on-failure
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,10 @@
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals>api</KeyPrefixEquals>
</Condition>
<Redirect>
<HostName>https://pmapi.jdbernard.com</HostName>
</Redirect>
</RoutingRule>
</RoutingRules>

76
deploy/doc.md Normal file
View File

@ -0,0 +1,76 @@
### Web App Hosting (static HTML)
Web app is deployed to an S3 bucket. Each top level directory in this bucket
represents a different deployed environment. For example:
s3://pm.jdb-labs.com
├── prod
│   ├── logs
│   │   └── cloudfront
│ └── webroot
   ├── css
   ├── img
   ├── js
   ├── index.html
│ └── ...
└── dev
   ├── logs
└── webroot
### API Hosting
API is served from razgriz:
* dev: https://pmapi-dev.jdb-labs.com (:80 -> :8281)
* prod: https://pmapi.jdb-labs.com (:80 -> :8280)
#### Server Setup Notes
The home folder of the `pmapi` user, like the S3 bucket, contains one folder
for each environment:
/home/pmapi
├── dev
│ ├── personal_measure_api
│ └── personal_measuer_api.config.json
└── prod
├── personal_measure_api
└── personal_measuer_api.config.json
As part of the automated deployment process, pmapi.jdb-labs.com has one systemd
service definitions for each environment. The sudoers file allows the `pmapi`
user to manage these without a password.
# Allow pmapi to manage the personal_measure_api service
pmapi ALL=NOPASSWD: /bin/systemctl stop personal_measure_api.prod.service
pmapi ALL=NOPASSWD: /bin/systemctl start personal_measure_api.prod.service
pmapi ALL=NOPASSWD: /bin/systemctl stop personal_measure_api.dev.service
pmapi ALL=NOPASSWD: /bin/systemctl start personal_measure_api.dev.service
two systemd
service definitions, one for
### Database
razgriz-db.jdb-labs.com RDS instance maintains databases for each environment:
* dev: `personal_measure_dev`
* prod: `personal_measure`
### Routing
CloudFront manages the routing of all of the external facing URLs.
https://pm.jdb-labs.com (CloudFront)
├── /api/<path>
│ └── https://pmapi.jdb-labs.com/api/
│ ├── nginx:80 --> nim/jester:8280
│ └── razgriz-db: database personal_measure
└── s3://pm.jdb-labs.com/prod/webroot (static HTML)
https://pm-dev.jdb-labs.com (CloudFront)
├── /api/<path>
│ └── https://pmapi-dev.jdb-labs.com/api/
│ ├── nginx:80 --> nim/jester:8281
│ └── razgriz-db: database personal_measure_dev
└── s3://pm.jdb-labs.com/dev/webroot (static HTML)

View File

@ -1,3 +0,0 @@
VUE_APP_PM_API_BASE=https://personal-measure.jdb-labs.com/api
VUE_APP_LOG_LEVEL=INFO
VUE_APP_API_LOG_LEVEL=ERROR

3
web/.env.production Normal file
View File

@ -0,0 +1,3 @@
VUE_APP_PM_API_BASE=https://pm.jdb-labs.com/api
VUE_APP_LOG_LEVEL=INFO
VUE_APP_API_LOG_LEVEL=ERROR

View File

@ -1,4 +1,3 @@
API_ADDR='localhost:8080'
API_LOG_LEVEL='WARN'
LOG_LEVEL='TRACE'

View File

@ -1,10 +1,10 @@
{
"name": "personal-measure-web",
"version": "0.1.0",
"version": "0.3.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"build": "vue-cli-service build --mode production",
"build-dev": "vue-cli-service build --mode development",
"lint": "vue-cli-service lint",
"test:unit": "vue-cli-service test:unit"

View File

@ -13,6 +13,7 @@ const logger = logService.getLogger('/app');
})
export default class App extends Vue {
public version = process.env.PM_VERSION;
private apiLogAppender!: ApiLogAppender;
private consoleLogAppender!: ConsoleLogAppender;

View File

@ -12,7 +12,7 @@ export class SimpleDetails extends Vue {
@Prop() private measure!: Measure<MeasureConfig>;
@Prop() private measurements!: Array<Measurement<MeasurementMeta>>;
private newMeasurement;
// private newMeasurement;
private moment = moment;
private chartOptions = {
noData: { text: 'no data',

View File

@ -1,3 +1,10 @@
const merge = require('deepmerge');
const VERSION = {
'process.env': {
PM_VERSION: JSON.stringify(require('./package.json').version)
}
};
module.exports = {
devServer: {
proxy: {
@ -17,5 +24,11 @@ module.exports = {
analyzerMode: 'static',
openAnalyzer: false
}
},
chainWebpack: config => {
config
.plugin('define')
.tap(args => merge(args, [VERSION]))
}
};