Skip to content

Commit

Permalink
release 2.0 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gavin committed Mar 23, 2021
1 parent 45cc115 commit 2e5d77a
Show file tree
Hide file tree
Showing 27 changed files with 253 additions and 469 deletions.
49 changes: 22 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,14 @@ Bootstrap 4 and the Bootstrap template Clean Blog is used as the base styling, b

Image | Base | Usage
------------ | ------------- | -------------
fe-custom | nginx:1.17.9 | frontend reverse proxy for Django
fe-custom | nginx:1.19.8 | frontend reverse proxy for Django
wagtail-custom | python:3.8-slim | Django with the Wagtail CMS
postgres-custom | postgres:12.0 | database instance for Django
redis-custom | redis:5.0.8 | cache for Django
smtp-custom | alpine:3.10 | mail relay for Django

- To follow best practice each image is built to run as a **non-root** user.
- To follow best practice each image supports Docker secrets.
- The **wagtail-custom** image is split into 2 Dockerfiles in case you would like to tweak and test the application code to suite your needs.
- Dockerfile 1, application requirements which takes some time to build
- Dockerfile 2, application code which has a quick build time


# Instructions
Assuming you have Docker installed, Docker Swarm initialized and you're not using Windows to host Docker - do the following.
Expand All @@ -54,27 +50,31 @@ vi build/mail/Dockerfile
vi build/app/Dockerfile
```

Build each image.
Build each image all at once.
```sh
cd build
./build.sh
```
Or build individually.
```sh
cd build/fe
./build-image.sh
./build.sh
```
```sh
cd build/db
./build-image.sh
./build.sh
```
```sh
cd build/cache
./build-image.sh
./build.sh
```
```sh
cd build/mail
./build-image.sh
./build.sh
```

```sh
cd build/app
./build-image.sh
./build.sh
```

### Prepare Server Files
Expand All @@ -93,6 +93,8 @@ persistance
system
```

Use the script under the `persistance` folder to make the necessary folders - `mkdir.sh`

### Create Certificates

For local testing, just use self-signed certificates.
Expand Down Expand Up @@ -153,27 +155,19 @@ echo -n "emailpassword" | docker secret create SMTP_PASSWORD -

### Edit Compose File



This variable controls whether the Nginx logs will be preserved across container restarts.
```yaml
x-fe-environment: &fe-environment
LOG_RETENTION: "false"
```
This section refers to application settings. Instead of using a menu management pacakge and templatetags, I have implemented search and replace in the startup of the **wagtail-custom** container for these values.
This section refers to application settings.
```yaml
x-app-environment: &app-environment
SITE_TITLE: "My Site"
SITE_FOOTER: 'Thanks for checking out My Site. Maybe consider visiting some of my social media accounts for more good stuff.'
A_SITE_NAV_SLUG: "home"
A_SITE_NAV_TITLE: "Home"
B_SITE_NAV_SLUG: "blog"
B_SITE_NAV_TITLE: "Blog"
C_SITE_NAV_SLUG: "archive"
C_SITE_NAV_TITLE: "Archive"
D_SITE_NAV_SLUG: "resume"
D_SITE_NAV_TITLE: "Resume"
E_SITE_NAV_SLUG: "contact"
E_SITE_NAV_TITLE: "Contact"
LINK_GITHUB: "https://github.com"
LINK_TELEGRAM: "https://telegram.org/"
LINK_YOUTUBE: "https://youtube.com"
Expand Down Expand Up @@ -224,7 +218,7 @@ resources:

Ensure the following files are in place. Every other unamed volume is an empty folder for logs or data.
```sh
persistance/app/img/error-page.jpg #this is displaying 403,404,500,etc
persistance/app/img/error-page.jpg #this is display upon 403,404,500 errors
persistance/app/img/favicon.ico #this is the icon displayed in the browser tab
```

Expand Down Expand Up @@ -292,9 +286,9 @@ To go along with these two scripts there are two cronjobs. Adjust the timing and
30 3 * * * source /home/user/.profile; /opt/docker-stacks/blog/system/scripts/exec-system-backup-cleaning.sh 2> /dev/null
```
# Optional Instruction - Customizing the Footer and Menu
# Optional Instruction - Customizing the Footer
You can edit 4 files to add/remove menu items and footer items.
You can edit these 4 files to add/remove footer items.
1. Add or remove an environment variable from `deploy/docker-compose.yml` for either the menu or footer.
1. Add or remove replacement commands from `build/app/code/service-init/run.sh` and rebuild the app image.
1. Add or remove a navigation or footer chunk from `build/app/code/service/base/templates/base.html` and `build/app/code/service/base/templates/base-default.html`
Expand All @@ -304,7 +298,7 @@ Look into glyphcons to find the right icons for your needs.
# Additional Notes
* Port 80 is exposed becaused nginx redirects http to https.
* `persistance/fe/conf/nginx.conf` can be edited to suite your needs but the default state will get an A+ on SSL Labs.
* `build/fe/code/service-init/nginx.conf` can be edited to suite your needs but the default state will get an A+ on SSL Labs.
* Build the `fe-custom` image with your edited conf file or map it in by adding a volume entry under **fe** service in the compose file.
`- "/opt/docker-stacks/blog/persistance/fe/conf/nginx.conf:/etc/nginx/nginx.conf"`
* To have the best cropping of your images these are the ideal dimensions
Expand All @@ -313,3 +307,4 @@ Look into glyphcons to find the right icons for your needs.
* Notes regarding gif files
* gif uploads are supported but Wagtail processing can be resource intensive upon initial upload
* gif files should be under 4MB
* This project supports wagtailmenus, see their documentation for creating a menu in the Wagtail UI.
123 changes: 117 additions & 6 deletions build/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
#set the source image
###################################################
FROM app-base:latest
LABEL maintainer="gavin"

#set vars, build time
#set vars, global build time
###################################################
ARG APP_UID=1000
ARG APP_GID=1000
Expand All @@ -12,6 +7,78 @@ ARG APP_GROUP=app
ARG APP_ROOT=/app
ARG CODE=code




#########################
#builder phase
#########################

#set the source image
###################################################
FROM python:3.8-slim AS builder
LABEL maintainer="gavin"

#set used global variables
###################################################
ARG APP_UID
ARG APP_GID
ARG APP_USER
ARG APP_GROUP
ARG APP_ROOT
ARG CODE

#run as root for setup
###################################################
USER root

#copy code
###################################################
RUN mkdir "$APP_ROOT" && mkdir "$APP_ROOT"/wheel-builder
COPY "$CODE"/ "$APP_ROOT"/

#app dependencies
###################################################
RUN apt-get update

RUN set -ex \
&& BUILD_DEPS=" \
gcc \
python3-dev \
libpq-dev \
libmagickwand-dev \
" \
&& apt-get install -y --no-install-recommends $BUILD_DEPS

RUN apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $BUILD_DEPS && \
rm -rf /var/lib/apt/lists/*

#python packages - build wheel
###################################################
RUN pip install --upgrade pip && \
pip wheel --no-cache-dir --no-deps --wheel-dir "$APP_ROOT"/wheel-builder -r "$APP_ROOT"/service-req/requirements.txt




#########################
#final phase
#########################

#set the source image
###################################################
FROM python:3.8-slim
LABEL maintainer="gavin"

#set used global variables
###################################################
ARG APP_UID
ARG APP_GID
ARG APP_USER
ARG APP_GROUP
ARG APP_ROOT
ARG CODE

#run as root for setup
###################################################
USER root
Expand All @@ -25,7 +92,10 @@ RUN groupadd -g "$APP_GID" "$APP_GROUP" && \

#copy code
###################################################
RUN mkdir "$APP_ROOT" && \
mkdir "$APP_ROOT"/wheel
COPY "$CODE"/ "$APP_ROOT"/
COPY --from=builder "$APP_ROOT"/wheel-builder/ "$APP_ROOT"/wheel/

#add other directories and modify permissions
###################################################
Expand All @@ -37,6 +107,47 @@ RUN mkdir /static && \
chmod +x "$APP_ROOT"/service-init/run.sh && \
chmod +x "$APP_ROOT"/service-init/create-user.sh

#python packages - use the pre-built wheel
###################################################
RUN pip install --upgrade pip && \
pip install --no-cache "$APP_ROOT"/wheel/* && \
rm -rf "$APP_ROOT"/wheel

#app dependencies
###################################################
RUN set -ex \
&& RUN_DEPS=" \
libexpat1 \
libjpeg62-turbo \
libpcre3 \
libpq5 \
mime-support \
procps \
zlib1g \
" \
&& seq 1 8 | xargs -I{} mkdir -p /usr/share/man/man{} \
&& apt-get update && apt-get install -y --no-install-recommends $RUN_DEPS

RUN set -ex \
&& BUILD_DEPS=" \
build-essential \
libexpat1-dev \
libjpeg62-turbo-dev \
libpcre3-dev \
libpq-dev \
zlib1g-dev \
gcc \
python3-dev \
libpq-dev \
netcat-openbsd \
iputils-ping \
libmagickwand-dev \
" \
&& apt-get install -y --no-install-recommends $BUILD_DEPS

RUN apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $BUILD_DEPS && \
rm -rf /var/lib/apt/lists/*

#set image defaults
###################################################
EXPOSE 8000
Expand Down
30 changes: 0 additions & 30 deletions build/app/build-image.sh

This file was deleted.

1 change: 1 addition & 0 deletions build/app/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker build -t wagtail-custom .
55 changes: 0 additions & 55 deletions build/app/code-base/Dockerfile

This file was deleted.

Loading

0 comments on commit 2e5d77a

Please sign in to comment.