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

Docker setup with nginx #588

Merged
merged 5 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This file uses a multi-stage build strategy. The build stage sets up the nvm environment and builds configurator, while the second stage copies this into a clean container without any build tools.

## First Stage- Build
FROM nginx as build
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8

# Pre-reqs
COPY conf/yarn.list /tmp
RUN apt update && \
apt install --no-install-recommends -y \
ca-certificates \
curl \
gnupg \
nodejs && \
mv /tmp/yarn.list /etc/apt/sources.list.d/yarn.list && \
curl https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
apt update -o Dir::Etc::sourcelist=/etc/apt/sources.list.d/yarn.list && \
apt install --no-install-recommends -y \
yarn && \
rm -rf /var/lib/apt/lists/*
RUN curl https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | bash

# Copy files into place
COPY . /qmk_configurator/

# Build configurator
RUN /bin/bash -i /qmk_configurator/bin/docker_build.sh
yanfali marked this conversation as resolved.
Show resolved Hide resolved

## Second Stage- Run
FROM nginx as run
EXPOSE 80/tcp

COPY --from=build /qmk_configurator/dist /qmk_configurator/dist
COPY conf/nginx.conf.in /etc/nginx/nginx.conf.in
COPY bin/docker_run.sh /qmk_configurator/docker_run.sh

CMD /bin/bash -i /qmk_configurator/docker_run.sh
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,29 @@ yarn run test:unit

### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).

## Docker

If you don't have a webserver already and don't already have one in mind you can use docker. By default it spins up a self-contained environment.

docker run -p 8080:80 qmkfm/qmk_configurator:latest

You can specify a different backend URL by setting `VUE_APP_API_URL`:

docker run -e VUE_APP_API_URL=http://localhost:8080 -p 8080:80 qmkfm/qmk_configurator:latest

If you'd like to develop locally you can use a volume to tie your local filesystem to the container:

docker run --mount type=volume,source=.,target=/qmk_configurator -p 8080:80 qmkfm/qmk_configurator:latest

### Building The Docker Image

Most of the time you don't need to do this, you can use volume mounts as described above to use the pre-built image with your local tree.

If for some reason you do need to build it yourself, you can use this command:

docker build -t qmk_configurator .

This process will take a while. You may want to go make some tea or something. When it finishes you can run it with this command:

docker run -p 8080:80 qmk_configurator
17 changes: 17 additions & 0 deletions bin/docker_build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
# Setup yarn and build qmk_configurator inside the docker container.

set -e
#set -x

# Install node
. /root/.nvm/nvm.sh
nvm install 11.12

# Setup configurator to build
cd /qmk_configurator
nvm use
yarn install

# Build configurator
VUE_APP_API_URL=/api yarn run build
24 changes: 24 additions & 0 deletions bin/docker_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh
# Setup yarn and build qmk_configurator inside the docker container.

set -e
#set -x

# Set the API URL
sed "s;%API_URL%;${QMK_API_URL:-https://api.qmk.fm};g" /etc/nginx/nginx.conf.in > /etc/nginx/nginx.conf

# Start nginx
cat << EOF
============================================================================
----------------------------------------------------------------------------

QMK Configurator is ready to go! You can access it at the following address:

http://localhost:8080

If you have chosen a port other than 8080 you may have to adjust that URL.

----------------------------------------------------------------------------
============================================================================
EOF
nginx -g 'daemon off;'
43 changes: 43 additions & 0 deletions conf/nginx.conf.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
worker_processes 2;

error_log /dev/fd/2 warn;
pid /var/run/nginx.pid;

events {
worker_connections 32;
}

http {
server_tokens off;
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /dev/fd/1 main;

sendfile off; # disable to avoid caching and volume mount issues
keepalive_timeout 65;

server {
listen 80 default_server;
root /qmk_configurator/dist;
index index.html;
server_name _;

location / {
try_files $uri $uri/ =404;
}

location /api/ {
rewrite ^/api(/.*)$ /$1 break;
proxy_pass %API_URL%;
}

location /docs/ {
root /qmk_compiler/qmk_firmware/docs;
}
}
}
1 change: 1 addition & 0 deletions conf/yarn.list
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deb http://dl.yarnpkg.com/debian/ stable main