mirror of
https://github.com/yldio/copilot.git
synced 2024-11-14 15:20:06 +02:00
feat(cp-frontend): use nginx instead of serve
This commit is contained in:
parent
5a86686933
commit
54a5c6a46e
@ -95,6 +95,8 @@ api:
|
||||
links:
|
||||
- consul:consul
|
||||
- rethinkdb:rethinkdb
|
||||
env_file:
|
||||
- _env
|
||||
environment:
|
||||
- CONSUL=consul
|
||||
- PORT=3000
|
||||
|
@ -1,15 +1,19 @@
|
||||
FROM quay.io/yldio/alpine-node-containerpilot:latest
|
||||
|
||||
RUN apk add --update nginx
|
||||
|
||||
ENV CONTAINERPILOT /etc/containerpilot.json5
|
||||
|
||||
RUN npm install -g npm@^4 \
|
||||
&& npm config set loglevel info \
|
||||
&& yarn add lerna@^2.0.0-rc.5 serve \
|
||||
&& ./node_modules/.bin/lerna clean --yes --scope joyent-cp-frontend --include-filtered-dependencies \
|
||||
&& ./node_modules/.bin/lerna bootstrap --scope joyent-cp-frontend --include-filtered-dependencies
|
||||
RUN npm install -g npm@^4
|
||||
RUN npm config set loglevel info \
|
||||
&& yarn add lerna@^2.0.0-rc.5
|
||||
|
||||
RUN ./node_modules/.bin/lerna clean --yes --scope joyent-cp-frontend --include-filtered-dependencies \
|
||||
&& ./node_modules/.bin/lerna bootstrap --scope joyent-cp-frontend --include-filtered-dependencies
|
||||
|
||||
COPY packages/cp-frontend/etc/containerpilot.json5 ${CONTAINERPILOT}
|
||||
COPY packages/cp-frontend/etc/nginx.conf.tmpl /etc/nginx/nginx.conf.tmpl
|
||||
|
||||
WORKDIR /opt/app/packages/cp-frontend
|
||||
|
||||
EXPOSE 3069
|
||||
CMD ["/bin/containerpilot"]
|
||||
|
@ -2,26 +2,28 @@
|
||||
consul: 'localhost:8500',
|
||||
jobs: [
|
||||
{
|
||||
name: 'build',
|
||||
exec: 'yarn run build'
|
||||
name: 'config-nginx',
|
||||
exec: 'containerpilot -config /etc/nginx/nginx.conf.tmpl -template -out /etc/nginx/nginx.conf'
|
||||
},
|
||||
{
|
||||
name: 'cp-frontend',
|
||||
port: {{.PORT}},
|
||||
exec: '../../node_modules/.bin/serve --single build --port {{.PORT}}',
|
||||
exec: 'nginx',
|
||||
interfaces: ["eth0", "eth1"],
|
||||
restarts: 'unlimited',
|
||||
when: {
|
||||
source: 'build',
|
||||
source: 'config-nginx',
|
||||
once: 'exitSuccess'
|
||||
},
|
||||
health: {
|
||||
exec: '/usr/bin/curl -o /dev/null --fail -s http://localhost:{{.PORT}}',
|
||||
interval: 2,
|
||||
ttl: 5
|
||||
interval: 5,
|
||||
ttl: 25
|
||||
},
|
||||
tags: [
|
||||
'traefik.backend=cp-frontend',
|
||||
'traefik.frontend.rule=PathPrefix:/',
|
||||
'traefik.frontend.entryPoints=http'
|
||||
'traefik.frontend.entryPoints={{ .ENTRYPOINTS | default "http,ws,wss" }}'
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -36,6 +38,18 @@
|
||||
'-retry-interval', '10s'],
|
||||
restarts: 'unlimited'
|
||||
},
|
||||
{
|
||||
name: 'is-built',
|
||||
exec: '[ -d /opt/app/packages/cp-frontend/build/static ]'
|
||||
},
|
||||
{
|
||||
name: 'build',
|
||||
exec: 'yarn run build',
|
||||
when: {
|
||||
source: 'is-built',
|
||||
once: 'exitFailed'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'sensor_memory_usage',
|
||||
exec: '/bin/sensors memory',
|
||||
|
101
packages/cp-frontend/etc/nginx.conf.tmpl
Normal file
101
packages/cp-frontend/etc/nginx.conf.tmpl
Normal file
@ -0,0 +1,101 @@
|
||||
# /etc/nginx/nginx.conf
|
||||
|
||||
user nginx;
|
||||
worker_processes 1;
|
||||
daemon off;
|
||||
|
||||
# Enables the use of JIT for regular expressions to speed-up their processing.
|
||||
pcre_jit on;
|
||||
|
||||
# Configures default error logger.
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
# Includes files with directives to load dynamic modules.
|
||||
include /etc/nginx/modules/*.conf;
|
||||
|
||||
|
||||
events {
|
||||
# The maximum number of simultaneous connections that can be opened by
|
||||
# a worker process.
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
index index.html index.htm;
|
||||
server {
|
||||
server_name _;
|
||||
listen {{ .PORT | default "80" }} default_server;
|
||||
listen [::]:{{ .PORT | default "80" }} default_server;
|
||||
root /opt/app/packages/cp-frontend/build;
|
||||
location / {
|
||||
try_files $uri /index.html;
|
||||
}
|
||||
}
|
||||
# Includes mapping of file name extensions to MIME types of responses
|
||||
# and defines the default type.
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
# Name servers used to resolve names of upstream servers into addresses.
|
||||
# It's also needed when using tcpsocket and udpsocket in Lua modules.
|
||||
#resolver 208.67.222.222 208.67.220.220;
|
||||
|
||||
# Don't tell nginx version to clients.
|
||||
server_tokens off;
|
||||
|
||||
# Specifies the maximum accepted body size of a client request, as
|
||||
# indicated by the request header Content-Length. If the stated content
|
||||
# length is greater than this size, then the client receives the HTTP
|
||||
# error code 413. Set to 0 to disable.
|
||||
client_max_body_size 1m;
|
||||
|
||||
# Timeout for keep-alive connections. Server will close connections after
|
||||
# this time.
|
||||
keepalive_timeout 65;
|
||||
|
||||
# Sendfile copies data between one FD and other from within the kernel,
|
||||
# which is more efficient than read() + write().
|
||||
sendfile on;
|
||||
|
||||
# Don't buffer data-sends (disable Nagle algorithm).
|
||||
# Good for sending frequent small bursts of data in real time.
|
||||
tcp_nodelay on;
|
||||
|
||||
# Causes nginx to attempt to send its HTTP response head in one packet,
|
||||
# instead of using partial frames.
|
||||
#tcp_nopush on;
|
||||
|
||||
# Path of the file with Diffie-Hellman parameters for EDH ciphers.
|
||||
#ssl_dhparam /etc/ssl/nginx/dh2048.pem;
|
||||
|
||||
# Specifies that our cipher suits should be preferred over client ciphers.
|
||||
ssl_prefer_server_ciphers on;
|
||||
|
||||
# Enables a shared SSL cache with size that can hold around 8000 sessions.
|
||||
ssl_session_cache shared:SSL:2m;
|
||||
|
||||
|
||||
# Enable gzipping of responses.
|
||||
#gzip on;
|
||||
|
||||
# Set the Vary HTTP header as defined in the RFC 2616.
|
||||
gzip_vary on;
|
||||
|
||||
# Enable checking the existence of precompressed files.
|
||||
#gzip_static on;
|
||||
|
||||
|
||||
# Specifies the main log format.
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
# Sets the path, format, and configuration for a buffered log write.
|
||||
access_log /var/log/nginx/access.log main;
|
||||
|
||||
|
||||
# Includes virtual hosts configs.
|
||||
# include /etc/nginx/conf.d/*.conf;
|
||||
}
|
@ -31,7 +31,7 @@ export const client = new ApolloClient({
|
||||
return `${o.__typename}:${id}`;
|
||||
},
|
||||
networkInterface: createNetworkInterface({
|
||||
uri: `http://${GQL_HOSTNAME}:${GQL_PORT}/graphql`
|
||||
uri: `http://${GQL_HOSTNAME}:${GQL_PORT}/api/graphql`
|
||||
})
|
||||
});
|
||||
|
||||
|
12
packages/portal-api/bootstrap-data.js
vendored
12
packages/portal-api/bootstrap-data.js
vendored
@ -17,11 +17,14 @@ const bootstrap = function () {
|
||||
}
|
||||
});
|
||||
|
||||
const region = process.env.TRITON_DC || 'us-sw-1';
|
||||
const login = process.env.TRITON_USER || 'nikola';
|
||||
|
||||
data.connect(() => {
|
||||
data.createDatacenter({ region: 'us-sw-1', name: 'us-sw-1' }, (err, datacenter) => {
|
||||
data.createDatacenter({ region, name: region }, (err, datacenter) => {
|
||||
ifError(err);
|
||||
|
||||
data.createUser({ firstName: 'Nikola', lastName: 'Tesla', email: 'nikola@tesla.com', login: 'nikola' }, (err, user) => {
|
||||
data.createUser({ firstName: 'Nikola', lastName: 'Tesla', email: 'nikola@tesla.com', login }, (err, user) => {
|
||||
ifError(err);
|
||||
|
||||
data.createPortal({
|
||||
@ -36,7 +39,7 @@ const bootstrap = function () {
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
const main = function () {
|
||||
const dropData = new Data({
|
||||
db: {
|
||||
@ -50,4 +53,5 @@ const main = function () {
|
||||
});
|
||||
});
|
||||
};
|
||||
main();
|
||||
*/
|
||||
bootstrap();
|
||||
|
@ -16,9 +16,13 @@
|
||||
},
|
||||
tags: [
|
||||
'traefik.backend=api',
|
||||
'traefik.frontend.rule=PathPrefix:/graphql,/graphiql',
|
||||
'traefik.frontend.rule=PathPrefixStrip:/api',
|
||||
'traefik.frontend.entryPoints=http'
|
||||
]
|
||||
],
|
||||
when: {
|
||||
source: 'bootstrap',
|
||||
once: 'exitSuccess'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'consul-agent',
|
||||
|
@ -28,6 +28,9 @@
|
||||
"dependencies": {
|
||||
"boom": "^5.1.0",
|
||||
"brule": "^2.0.0",
|
||||
"good": "^7.2.0",
|
||||
"good-console": "^6.4.0",
|
||||
"good-squeeze": "^5.0.2",
|
||||
"graphi": "^2.2.1",
|
||||
"hoek": "^4.1.1",
|
||||
"joi": "^10.6.0",
|
||||
|
@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const Brule = require('brule');
|
||||
const Good = require('good');
|
||||
const Hapi = require('hapi');
|
||||
const HapiSwagger = require('hapi-swagger');
|
||||
const Inert = require('inert');
|
||||
@ -10,12 +11,7 @@ const Pack = require('./package');
|
||||
const Portal = require('./lib');
|
||||
|
||||
const server = new Hapi.Server();
|
||||
server.connection({
|
||||
port: 3000,
|
||||
routes: {
|
||||
cors: true
|
||||
}
|
||||
});
|
||||
server.connection({ port: 3000 });
|
||||
|
||||
const swaggerOptions = {
|
||||
info: {
|
||||
@ -32,10 +28,29 @@ const portalOptions = {
|
||||
}
|
||||
};
|
||||
|
||||
const goodOptions = {
|
||||
ops: {
|
||||
interval: 1000
|
||||
},
|
||||
reporters: {
|
||||
consoleReporter: [{
|
||||
module: 'good-squeeze',
|
||||
name: 'Squeeze',
|
||||
args: [{ log: '*', response: '*', error: '*' }]
|
||||
}, {
|
||||
module: 'good-console'
|
||||
}, 'stdout']
|
||||
}
|
||||
};
|
||||
|
||||
server.register([
|
||||
Brule,
|
||||
Inert,
|
||||
Vision,
|
||||
{
|
||||
register: Good,
|
||||
options: goodOptions
|
||||
},
|
||||
{
|
||||
register: Portal,
|
||||
options: portalOptions
|
||||
|
5
setup.sh
5
setup.sh
@ -24,10 +24,15 @@ check() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
TRITON_USER=$(triton profile get | awk -F": " '/account:/{print $2}')
|
||||
TRITON_DC=$(triton profile get | awk -F"/" '/url:/{print $3}' | awk -F'.' '{print $1}')
|
||||
|
||||
echo '# docker-compose-client for Triton' > _env
|
||||
TRITON_CREDS_PATH=/root/.triton
|
||||
echo TRITON_CREDS_PATH=${TRITON_CREDS_PATH} >> _env
|
||||
echo DOCKER_CERT_PATH=${TRITON_CREDS_PATH} >> _env
|
||||
echo TRITON_USER=${TRITON_USER} >> _env
|
||||
echo TRITON_DC=${TRITON_DC} >> _env
|
||||
echo TRITON_CA=$(cat "${DOCKER_CERT_PATH}"/ca.pem | tr '\n' '#') >> _env
|
||||
echo TRITON_CA_PATH=${TRITON_CREDS_PATH}/ca.pem >> _env
|
||||
echo TRITON_KEY=$(cat "${DOCKER_CERT_PATH}"/key.pem | tr '\n' '#') >> _env
|
||||
|
Loading…
Reference in New Issue
Block a user