Skip to content

Commit

Permalink
Convert Flask app to nginx
Browse files Browse the repository at this point in the history
This removes the Fask app with app.py and adds nginx configuration.
The run script, docker files, and package.json have been updated in line with this.
  • Loading branch information
WillMoggridge committed Aug 20, 2018
1 parent 74f49f9 commit 0483ced
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 417 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ venv/
.envrc

# Data, compiled, build or log files
build/
develop-eggs/
dist/
downloads/
Expand Down
20 changes: 11 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ ENV LANG C.UTF-8
WORKDIR /srv

# System dependencies
RUN apt-get update && apt-get install --yes python3-pip

# Import code, install code dependencies
ADD . .
RUN pip3 install -r requirements.txt
RUN apt-get update && apt-get install --yes nginx

# Set git commit ID
ARG COMMIT_ID
RUN test -n "${COMMIT_ID}"
RUN echo "${COMMIT_ID}" > version-info.txt

# Setup commands to run server
ENTRYPOINT ["./entrypoint"]
CMD ["0.0.0.0:80"]
# Copy over files
ADD build .
ADD nginx.conf /etc/nginx/sites-enabled/default
ADD redirects.map /etc/nginx/redirects.map
RUN sed -i "s/~COMMIT_ID~/${COMMIT_ID}/" /etc/nginx/sites-enabled/default
RUN sed -i "s/8203/80/" /etc/nginx/sites-enabled/default

STOPSIGNAL SIGTERM

CMD ["nginx", "-g", "daemon off;"]

98 changes: 0 additions & 98 deletions app.py

This file was deleted.

5 changes: 0 additions & 5 deletions entrypoint

This file was deleted.

55 changes: 55 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
map $uri $target {
include redirects.map;
}

server {
listen 8203 default_server;
listen [::]:8203 default_server;
server_name _;

# Log to stdout
access_log /dev/stdout;
error_log /dev/stderr info;

root /srv;

index index.html;

# Show 404 page
error_page 404 /404.html;

# Show commit-id
add_header X-Commit-ID ~COMMIT_ID~ always;
add_header X-Hostname $hostname always;

# Apply redirects from file
if ($target) {
rewrite ^ $target redirect;
}

# Remove index or index.html from URIs
if ($request_uri ~ ^.*/index$) {
rewrite ^(.*/)index$ $1 permanent;
}
if ($request_uri ~ ^.*/index.html$) {
rewrite ^(.*/)index.html$ $1 permanent;
}

# Remove .html from URIs
if ($request_uri ~ ^.*\.html$) {
rewrite ^(.*)\.html$ $1 permanent;
}

# Remove slashes form URIs if it's not a directory
if (!-d $request_filename) {
rewrite ^/(.*)/$ /$1 permanent;
}

# Add slashes from URIs if it's a directory
if (-d $request_filename) {
rewrite ^/(.*[^/])$ /$1/ permanent;
}

try_files $uri $uri.html $uri/ =404;
}

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
"scripts": {
"clean": "rm -rf node_modules yarn-error.log css static/css *.log *.sqlite build/ .extra templates",
"watch": "watch -p './**/*.md' -c 'yarn run build-css'",
"build": "documentation-builder --base-directory . --output-path templates --output-media-path 'static/media' --media-url '/static/media' --tag-manager-code 'GTM-K92JCQ' --search-domain 'docs.maas.io' --search-url 'https://docs.ubuntu.com/search' --search-placeholder 'Search MAAS docs' --no-link-extensions --build-version-branches --site-root https://maas.io/",
"test": "",
"serve": "./entrypoint 0.0.0.0:$PORT"
"build": "documentation-builder --base-directory . --output-path build --output-media-path 'build/media' --media-url '/media' --tag-manager-code 'GTM-K92JCQ' --search-domain 'docs.maas.io' --search-url 'https://docs.ubuntu.com/search' --search-placeholder 'Search MAAS docs' --no-link-extensions --build-version-branches --site-root https://maas.io/"
},
"dependencies": {
"watch-cli": "^0.2.2"
Expand Down
19 changes: 19 additions & 0 deletions redirects.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
~^/(|en/?|2.4.0/?)?$ /2.4/en/;
~^/en/(?<page>.+)$ /2.4/en/${page};
~^/(?<version>[0-9-\._]+|devel)(/|/index)?$ /${version}/en/;
~^/(?<version>[0-9-\._]+|devel)/(?<language>[a-zA-Z]+)(/index)?$ /${version}/${language}/;

/devel/en/intel-rsd /devel/en/nodes-comp-hw;
/2.1/en/installconfig-deploy-nodes /2.1/en/installconfig-nodes-deploy;
/2.1/en/installconfig-gui /2.1/en/installconfig-webui;
/2.1/en/installconfig-hwe-kernels /2.1/en/installconfig-nodes-ubuntu-kernels;
/2.1/en/installconfig-kernel /2.1/en/installconfig-nodes-kernel-boot-options;
/2.1/en/installconfig-server-iso /2.1/en/installconfig-iso-install;
/2.1/en/installconfig-commisson-nodes /2.1/en/nodes-commission;
/2.1/en/installconfig-add-nodes /2.1/en/nodes-add;
/2.2/en/installconfig-nodes-hw-testing /2.2/en/nodes-hw-testing;
/2.2/en/installconfig-add-nodes /2.2/en/nodes-add;
/2.2/en/installconfig-commisson-nodes /2.2/en/nodes-commission;
/2.2/en/installconfig-nodes-deploy /2.2/en/nodes-deploy;
/2.2/en/installconfig-nodes-power-types /2.2/en/nodes-power-types;
/2.2/en/intel-rsd /2.2/en/nodes-comp-hw;
18 changes: 0 additions & 18 deletions redirects.yaml

This file was deleted.

8 changes: 1 addition & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
Flask==0.12.2
PyYAML==3.12
pycountry==17.9.23
yamlordereddictloader==0.4.0
ubuntudesign.documentation-builder==1.6.0
talisker==0.9.13
gunicorn[gevent]
ubuntudesign.documentation-builder==1.5.3
Loading

0 comments on commit 0483ced

Please sign in to comment.