Skip to content
Draft
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
27 changes: 27 additions & 0 deletions .config/containers/systemd/nginx.container
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[Unit]
Description=Hackspace web proxy
After=website.container
Requires=website.container

[Container]
ContainerName=HSNginx
Image=nginx:alpine

# Intended location
#Volume=/srv/nginx/nginx.conf:/etc/nginx/nginx.conf
#Volume=./nginx/.ssl:/etc/nginx/.ssl:ro

# if you have it on a dev box
Volume=/home/<USER>/Projects/website/nginx/nginx.conf:/etc/nginx/nginx.conf
Volume=/home/<USER>/Projects/website/nginx/.ssl:/etc/nginx/.ssl:ro

PublishPort=8080:80
PublishPort=8443:443
Network=nginx.network

[Service]
Restart=always

[Install]
WantedBy=default.target

2 changes: 2 additions & 0 deletions .config/containers/systemd/nginx.network
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Network]
# This creates a bridge network where containers can resolve each other by name
16 changes: 16 additions & 0 deletions .config/containers/systemd/website.container
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=Hackspace Website

[Container]
ContainerName=website
Image=localhost/website
UserNS=keep-id
# PublishPort=5000:5000
Network=nginx.network

[Service]
Restart=always

[Install]
WantedBy=default.target

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,8 @@ cython_debug/
#.idea/
.bash_history
.python_history

# Certificates count as secrets so shouldn't go on Git.
*.key
*.crt
*.pem
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# syntax=docker/dockerfile:1

FROM python:slim
# WORKDIR /app
COPY . .
# RUN apt-get update && apt-get install -y python3.11 python3-pip
ENV PIP_ROOT_USER_ACTION=ignore
RUN pip install -r requirements.txt
ENV FLASK_APP hackspace_website:create_app
ENV FLASK_ENV development
EXPOSE 5000
#CMD ["flask"]
ENTRYPOINT ["flask", "run", "--host=0.0.0.0"]

15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,18 @@ WARNING: This is a development server. Do not use it in a production deployment.
```

With the server running, in a browser navigate to: http://127.0.0.1:5000


# Container!

You can stand up the container with `podman-compose up --build`

you'll need ssl certs if you want to use ssl (and don't have them set up for your dev environment yet). I do NOT recommend using this in production - HS already has a working certificate process.
```
# Interactive
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 365 -subj '/CN=localhost' -nodes

# Non-interactive and 10 years expiration
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 3650 -nodes -subj "/C=XX/ST=StateName/L=CityName/O=CompanyName/OU=CompanySectionName/CN=CommonNameOrHostname"
```
https://stackoverflow.com/questions/10175812/how-can-i-generate-a-self-signed-ssl-certificate-using-openssl
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: "3"
services:
website:
build:
context: .
ports:
- "5000:5000"
nginx:
image: nginx:alpine
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf # :ro
- ./nginx/.ssl:/etc/nginx/.ssl:ro
depends_on:
- website
ports:
- "9000:80"
- "9443:443"

1 change: 1 addition & 0 deletions hackspace_website/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def create_app(test_config=None):
app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping(
SQLALCHEMY_DATABASE_URI="postgresql+psycopg2://postgres:postgres@localhost:5432/website",
# Does the website rely on our internal postgresql instance? if so, change from localhost
MESSAGE_RATELIMIT_WINDOW=timedelta(minutes=10).total_seconds(),
MESSAGE_RATELIMIT_COUNT=3,
RECOMMENDED_PAYMENT_URL="http://example.com/recommended",
Expand Down
1 change: 1 addition & 0 deletions nginx/.ssl/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The .gitignore removes any certs you put in this folder, but this is where the docker-compose will look for them.
29 changes: 29 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
events {
worker_connections 1024;
}
worker_processes auto;
http{
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;

# server{
# server_name website;
# listen 80;
# location / {
# proxy_pass http://website:5000;

# }
# }
server {
server_name website;
listen 80;
listen 443 ssl;
ssl_certificate .ssl/cert.pem;
ssl_certificate_key .ssl/key.pem;
location / {
proxy_pass http://website:5000;
# proxy_pass http://localhost:5000;
}
keepalive_timeout 70;
}
}