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

QF-3892 Create custom nginx docker image for QFC #898

Merged
merged 10 commits into from
Mar 11, 2024
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
13 changes: 13 additions & 0 deletions .github/workflows/build_and_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,16 @@ jobs:
tags: |
opengisch/qfieldcloud-qgis:${{ steps.prepare.outputs.docker_tag }}
opengisch/qfieldcloud-qgis:${{ steps.prepare.outputs.docker_commit }}

# Nginx
- name: Docker Build and Push nginx
id: docker_build_and_push_nginx
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
context: ./docker-nginx
file: ./docker-nginx/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: |
opengisch/qfieldcloud-nginx:${{ steps.prepare.outputs.docker_tag }}
opengisch/qfieldcloud-nginx:${{ steps.prepare.outputs.docker_commit }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ __pycache__/
.env
docker-compose.override.yml
client/projects
conf/nginx/certs/*
docker-nginx/certs/*
conf/certbot/*
Pipfile*
**/site-packages
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,11 @@ Note if you run tests using the `docker-compose.test.yml` configuration, the `ap

## Add root certificate

QFieldCloud will automatically generate a certificate and it's root certificate in `./config/nginx/certs`. However, you need to trust the root certificate first, so other programs (e.g. curl) can create secure connection to the local QFieldCloud instance.
QFieldCloud will automatically generate a certificate and it's root certificate in `./docker-nginx/certs`. However, you need to trust the root certificate first, so other programs (e.g. curl) can create secure connection to the local QFieldCloud instance.

On Debian/Ubuntu, copy the root certificate to the directory with trusted certificates. Note the extension has been changed to `.crt`:

sudo cp ./conf/nginx/certs/rootCA.pem /usr/local/share/ca-certificates/rootCA.crt
sudo cp ./docker-nginx/certs/rootCA.pem /usr/local/share/ca-certificates/rootCA.crt

Trust the newly added certificate:

Expand Down
11 changes: 4 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,11 @@ services:
ofelia.job-exec.runcrons.command: python manage.py runcrons

nginx:
image: nginx:stable
build:
context: ./docker-nginx
restart: unless-stopped
volumes:
- ./conf/nginx/pages/:/var/www/html/pages/
- ./conf/nginx/templates/:/etc/nginx/templates/
- ./conf/nginx/certs/:/etc/nginx/certs/:ro
- ./conf/nginx/options-ssl-nginx.conf:/etc/nginx/options-ssl-nginx.conf
- ./conf/nginx/ssl-dhparams.pem:/etc/nginx/ssl-dhparams.pem
- ./docker-nginx/certs/:/etc/nginx/certs/:ro
- certbot_www:/var/www/certbot
ports:
- ${WEB_HTTP_PORT}:80
Expand All @@ -119,7 +116,7 @@ services:
environment:
domain: ${QFIELDCLOUD_HOST}
volumes:
- ./conf/nginx/certs/:/root/.local/share/mkcert/
- ./docker-nginx/certs/:/root/.local/share/mkcert/
command: /bin/sh -c 'mkcert -install && for i in $$(echo $$domain | sed "s/,/ /g"); do [ ! -f /root/.local/share/mkcert/$$i.pem ] && mkcert $$i; done && tail -f -n0 /etc/hosts'

certbot:
Expand Down
6 changes: 6 additions & 0 deletions docker-nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM nginx:stable

COPY pages /var/www/html/pages/
COPY templates/ /etc/nginx/templates/
COPY options-ssl-nginx.conf /etc/nginx/options-ssl-nginx.conf
COPY ssl-dhparams.pem /etc/nginx/ssl-dhparams.pem
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
10 changes: 5 additions & 5 deletions scripts/init_letsencrypt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ set +o allexport

CONFIG_PATH="${CONFIG_PATH:-'./conf'}"

if [ ! -e "$CONFIG_PATH/nginx/options-ssl-nginx.conf" ] || [ ! -e "$CONFIG_PATH/nginx/ssl-dhparams.pem" ]; then
if [ ! -e "docker-nginx/options-ssl-nginx.conf" ] || [ ! -e "docker-nginx/ssl-dhparams.pem" ]; then
echo "### Downloading recommended TLS parameters ..."
curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/_internal/tls_configs/options-ssl-nginx.conf > "$CONFIG_PATH/nginx/options-ssl-nginx.conf"
curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot/certbot/ssl-dhparams.pem > "$CONFIG_PATH/nginx/ssl-dhparams.pem"
curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/_internal/tls_configs/options-ssl-nginx.conf > "docker-nginx/options-ssl-nginx.conf"
curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot/certbot/ssl-dhparams.pem > "docker-nginx/ssl-dhparams.pem"
echo
fi

Expand All @@ -34,8 +34,8 @@ docker compose run --rm --entrypoint "\
echo

echo "### Copy the certificate and key to their final destination ..."
cp ${CONFIG_PATH}/certbot/conf/live/${QFIELDCLOUD_HOST}/fullchain.pem ${CONFIG_PATH}/nginx/certs/${QFIELDCLOUD_HOST}.pem
cp ${CONFIG_PATH}/certbot/conf/live/${QFIELDCLOUD_HOST}/privkey.pem ${CONFIG_PATH}/nginx/certs/${QFIELDCLOUD_HOST}-key.pem
cp ${CONFIG_PATH}/certbot/conf/live/${QFIELDCLOUD_HOST}/fullchain.pem docker-nginx/certs/${QFIELDCLOUD_HOST}.pem
cp ${CONFIG_PATH}/certbot/conf/live/${QFIELDCLOUD_HOST}/privkey.pem docker-nginx/certs/${QFIELDCLOUD_HOST}-key.pem
echo

echo "### Reloading nginx ..."
Expand Down
Loading