Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better scripts #1000

Merged
merged 2 commits into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ ENV NODE_ENV ${NODE_ENV:-production}
ENV MAIN_RPC_ADDR=main.jnode.network
ENV ROPSTEN_RPC_ADDR=ropsten.jnode.network

RUN wget -q https://github.com/jibrelnetwork/dockerize/releases/latest/download/dockerize-alpine-linux-amd64-latest.tar.gz \
&& tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-latest.tar.gz \
&& rm dockerize-alpine-linux-amd64-latest.tar.gz

COPY docker/nginx.tpl.conf /etc/nginx/nginx.tpl.conf
COPY docker/run.sh /bin/run.sh

COPY --from=build /app/build/. /app/
COPY --from=build /app/docs/. /docs/
COPY version.txt /app/
COPY docker/nginx /etc/nginx/
COPY docker/run.sh /bin/run.sh

RUN ["run.sh", "check"]
CMD ["run.sh", "start"]
12 changes: 11 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
builder()
builder(
buildTasks: [
[
name: 'Nginx Checks',
type: 'test',
method: 'inside',
runAsUser: 'root',
command: 'run.sh check',
],
],
)
9 changes: 7 additions & 2 deletions docker/nginx/nginx.conf → docker/nginx.tpl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ http {
gzip_static on; #http://nginx.org/ru/docs/http/ngx_http_gzip_static_module.html

server {
listen 80 default_server;
listen {{ default .Env.HTTP_PORT "80" }} default_server;
index index.html;

location / {
Expand All @@ -55,6 +55,11 @@ http {
stub_status;
}

include /etc/nginx/includes/*.conf;
{{ if or .Env.STORYBOOK (eq (default .Env.ENVIRONMENT "production") "demo") }}
location /storybook {
root /docs;
try_files $uri $uri/ /index.html;
}
{{ end }}
}
}
Empty file removed docker/nginx/includes/.gitkeep
Empty file.
4 changes: 0 additions & 4 deletions docker/nginx/templates/include-demo.conf

This file was deleted.

32 changes: 17 additions & 15 deletions docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@
RUNMODE="${1:-start}"
ENVIRONMENT="${ENV:-undefined}"

if [ "${RUNMODE}" = "check" ]; then
# Copy all available configs for checking them
cp /etc/nginx/templates/*.conf /etc/nginx/includes 2>/dev/null
function prepare_and_check() {
env $@ sh -c 'dockerize -template /etc/nginx/nginx.tpl.conf:/etc/nginx/nginx.conf'
/usr/sbin/nginx -t
# Remove includes after checking
rm -rf /etc/nginx/includes/*
}

if [ "${RUNMODE}" = "check" ]; then
echo "Checking default configuration..."
prepare_and_check

echo "Checking demo mode..."
prepare_and_check STORYBOOK=1

echo "Checking demo mode (legacy option)..."
prepare_and_check ENVIRONMENT=demo

echo "Checks were completed successfully"
else
echo "Starting jwallet-web service, version: `cat /app/version.txt` on node `hostname`, mode: ${ENVIRONMENT}"

# Enable includes based on environment mode
cp /etc/nginx/templates/*-${ENVIRONMENT}.conf /etc/nginx/includes 2>/dev/null || true

for envvar in MAIN_RPC_ADDR MAIN_RPC_PORT ROPSTEN_RPC_ADDR ROPSTEN_RPC_PORT; do
if [ $(eval echo "\$${envvar}") ]; then
echo "Setting ${envvar} to $(eval echo "\$${envvar}")"
sed -i -- "s/\[${envvar}\]/$(eval echo "\$${envvar}")/g" /app/js/settings.js
fi
done
echo "Ready"
dockerize -template /etc/nginx/nginx.tpl.conf:/etc/nginx/nginx.conf \
-template /app/js/settings.js:/app/js/settings.js

/usr/sbin/nginx
fi
12 changes: 6 additions & 6 deletions src/public/js/settings.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
window.__MAIN_RPC_ADDR__ = '[MAIN_RPC_ADDR]'
window.__MAIN_RPC_PORT__ = '[MAIN_RPC_PORT]'
window.__MAIN_RPC_ADDR__ = '{{ default .Env.MAIN_RPC_ADDR "main.jnode.network" }}'
window.__MAIN_RPC_PORT__ = '{{ default .Env.MAIN_RPC_PORT "443" }}'

window.__ROPSTEN_RPC_ADDR__ = '[ROPSTEN_RPC_ADDR]'
window.__ROPSTEN_RPC_PORT__ = '[ROPSTEN_RPC_PORT]'
window.__ROPSTEN_RPC_ADDR__ = '{{ default .Env.ROPSTEN_RPC_ADDR "ropsten.jnode.network" }}'
window.__ROPSTEN_RPC_PORT__ = '{{ default .Env.ROPSTEN_RPC_PORT "443" }}'

window.__TICKER_API__ = '[TICKER_API]'
window.__BLOCKEXPLORER_API__ = '[BLOCKEXPLORER_API]'
window.__TICKER_API__ = '{{ default .Env.TICKER_API "" }}'
window.__BLOCKEXPLORER_API__ = '{{ default .Env.BLOCKEXPLORER_API "" }}'