Skip to content

Commit ff28fc2

Browse files
authored
chore: bump things and update documentation (#75)
* bump things and update documentation updated python to 3.11 added python setup guide to readme, comments to config files etc merged deploy and docker build CI steps added working mypy configuration (commented out because mypy is disabled for some reason) removed all 57 build time dependencies fixed a few lints * typo * remove newline * mention env settings * forgot actual dependency install step * hide venv inside spoiler
1 parent f65f4bd commit ff28fc2

File tree

9 files changed

+258
-211
lines changed

9 files changed

+258
-211
lines changed

.github/workflows/main.yml

Lines changed: 38 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,68 +17,58 @@ jobs:
1717
lint:
1818
runs-on: ubuntu-latest
1919
steps:
20-
- uses: actions/checkout@v3
21-
- uses: actions/setup-python@v4
22-
with:
23-
python-version: '3.10'
24-
- uses: pre-commit/[email protected]
20+
- uses: actions/checkout@v4
21+
- uses: actions/setup-python@v4
22+
with:
23+
python-version: '3.11'
24+
- uses: pre-commit/[email protected]
2525

2626
unit_test:
2727
needs: [ lint ]
2828
runs-on: ubuntu-latest
2929
steps:
30-
- uses: actions/checkout@v3
31-
- uses: actions/setup-python@v4
32-
with:
33-
python-version: '3.10'
34-
- name: Install dependencies
35-
run: |
36-
pip install poetry
37-
poetry config virtualenvs.create false
38-
poetry install
39-
- name: Run tests
40-
env:
41-
SECRET_KEY: secret
42-
DB_ENGINE: django.db.backends.sqlite3
43-
run: |
44-
cd src
45-
python manage.py migrate
46-
python manage.py test tests/
30+
- uses: actions/checkout@v4
31+
- uses: actions/setup-python@v4
32+
with:
33+
python-version: '3.11'
34+
- name: Install dependencies
35+
run: |
36+
pip install poetry
37+
poetry config virtualenvs.create false
38+
poetry install
39+
- name: Run tests
40+
env:
41+
SECRET_KEY: secret
42+
DB_ENGINE: django.db.backends.sqlite3
43+
run: |
44+
cd src
45+
python manage.py migrate
46+
python manage.py test tests/
4747
48-
build_docker:
49-
needs: [ lint ]
50-
runs-on: ubuntu-latest
51-
steps:
52-
- uses: actions/checkout@v3
53-
- name: Build Docker image
54-
run: |
55-
docker pull $IMAGE_NAME
56-
docker build --pull --cache-from $IMAGE_NAME -t $IMAGE_NAME .
57-
58-
deploy:
59-
needs: [ unit_test, build_docker ]
60-
if: ${{ github.event_name == 'push' }}
48+
docker:
49+
needs: [ lint, unit_test ]
6150
runs-on: ubuntu-latest
6251
steps:
63-
- uses: actions/checkout@v3
64-
- uses: actions/checkout@v2
65-
- name: Build image
66-
run: |
67-
docker pull $IMAGE_NAME
68-
docker build --pull --cache-from $IMAGE_NAME -t $IMAGE_NAME:latest .
52+
- uses: actions/checkout@v4
53+
- name: Build docker image
54+
run: |
55+
docker pull $IMAGE_NAME
56+
docker build --pull --cache-from $IMAGE_NAME -t $IMAGE_NAME:latest .
6957
70-
- name: Log in into Docker Hub
71-
run: |
72-
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
58+
- name: Log in into Docker Hub
59+
if: ${{ github.event_name == 'push' }}
60+
run: |
61+
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
7362
7463
# Context:
75-
# For some reason, commits from semantic-release bot do not trigger any actions.
64+
# For some reason, commits from semantic-release bot does not trigger any actions.
7665
# Build/push steps were copied into release workflow until we figure out a better way.
7766
# - name: Add a release tag to image
7867
# if: contains(github.ref, 'refs/tags/')
7968
# run: |
8069
# docker tag $IMAGE_NAME $IMAGE_NAME:${GITHUB_REF#refs/tags/}
8170

82-
- name: Push image to registry
83-
run: |
84-
docker push $IMAGE_NAME
71+
- name: Push image to registry
72+
if: ${{ github.event_name == 'push' }}
73+
run: |
74+
docker push $IMAGE_NAME

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
repos:
22
- repo: https://github.com/ambv/black
3-
rev: 23.3.0
3+
rev: 23.12.1
44
hooks:
55
- id: black
66

77
- repo: https://github.com/astral-sh/ruff-pre-commit
8-
rev: v0.0.270
8+
rev: v0.1.13
99
hooks:
1010
- id: ruff
1111
args: [ --fix, --exit-non-zero-on-fix ]
1212

1313
- repo: https://github.com/pre-commit/pre-commit-hooks
14-
rev: v4.4.0
14+
rev: v4.5.0
1515
hooks:
1616
- id: check-added-large-files
1717
- id: check-case-conflict
@@ -28,6 +28,6 @@ repos:
2828
^.*.md$
2929
3030
# - repo: https://github.com/pre-commit/mirrors-mypy
31-
# rev: v0.782
31+
# rev: v1.8.0
3232
# hooks:
3333
# - id: mypy

Dockerfile

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,47 @@
1-
FROM python:3.10.6-alpine3.16
1+
FROM python:3.11-alpine3.19
22

3-
# enables proper stdout flushing
4-
ENV PYTHONUNBUFFERED yes
3+
# in order:
4+
# proper stdout flushing for alpine
55
# no .pyc files
6-
ENV PYTHONDONTWRITEBYTECODE yes
7-
8-
# pip optimizations
9-
ENV PIP_NO_CACHE_DIR yes
10-
ENV PIP_DISABLE_PIP_VERSION_CHECK yes
6+
# do not store pip cache
7+
# do not check pip version
8+
# do not yell about root user
9+
ENV PYTHONUNBUFFERED=yes \
10+
PYTHONDONTWRITEBYTECODE=yes \
11+
PIP_NO_CACHE_DIR=1 \
12+
PIP_DISABLE_PIP_VERSION_CHECK=1 \
13+
PIP_ROOT_USER_ACTION=ignore
1114

1215
WORKDIR /src
1316

14-
COPY poetry.lock pyproject.toml ./
15-
16-
RUN apk add --no-cache libpq \
17-
&& apk add --no-cache --virtual .build-deps \
18-
# https://cryptography.io/en/latest/installation/#alpine
19-
gcc \
20-
musl-dev \
21-
python3-dev \
22-
libffi-dev \
23-
openssl-dev \
24-
cargo \
25-
postgresql-dev \
17+
COPY poetry.lock pyproject.toml .
18+
19+
RUN : \
20+
# psycopg runtime dep
21+
&& apk add --no-cache libpq \
2622
&& pip install poetry \
2723
&& poetry config virtualenvs.create false \
28-
&& poetry install --no-dev \
29-
&& apk del --purge .build-deps
24+
&& poetry install --only main
3025

3126
COPY src .
3227

33-
RUN mkdir /home/website
34-
RUN mkdir /home/website/statics
35-
RUN mkdir /home/website/media
36-
3728
# I'm too dumb to make user permissions over shared volumes work
38-
#RUN addgroup -S unitystation \
39-
# && adduser -S central_command -G unitystation \
40-
# && chown -R central_command:unitystation /src \
41-
# && chown -R central_command:unitystation $home
29+
# RUN : \
30+
# && addgroup -S unitystation \
31+
# && adduser -S central_command -G unitystation \
32+
# && chown -R central_command:unitystation /src
4233
#
43-
#USER central_command
34+
# USER central_command
35+
36+
RUN : \
37+
&& mkdir /home/website \
38+
&& mkdir /home/website/statics \
39+
&& mkdir /home/website/media
4440

45-
RUN sed -i 's/\r$//g' entrypoint.sh
46-
RUN chmod +x entrypoint.sh
41+
# removes \r from script and makes it executable.
42+
# both of these are caused by windows users touching file and not configuring git properly
43+
RUN : \
44+
&& sed -i 's/\r//g' entrypoint.sh \
45+
&& chmod +x entrypoint.sh
4746

48-
ENTRYPOINT ["./entrypoint.sh"]
47+
ENTRYPOINT ["./entrypoint.sh"]

README.md

Lines changed: 71 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,91 @@
11
# Central Command
2+
23
![Docker Image Version (latest by date)](https://img.shields.io/docker/v/unitystation/central-command?sort=date)
34
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/38cce37d4c854ca48645fd5ecc9cae61)](https://www.codacy.com/gh/unitystation/central-command/dashboard?utm_source=github.com&utm_medium=referral&utm_content=unitystation/central-command&utm_campaign=Badge_Grade)
45

56
The all-in-one backend application for [Unitystation](https://github.com/unitystation/unitystation)
67

7-
### Features
8-
- Account managment and user validation.
9-
- Server list managment.
8+
## Features
9+
10+
- Account management and user validation.
11+
- Server list management.
1012
- In-game persistence.
1113
- Works cross-fork!
1214
- Modular architecture.
1315

14-
### Development guide
15-
#### Setting up Docker
16+
## Development guide
1617

17-
1- To get started with docker, install it from [here](https://docs.docker.com/get-docker/) and (optionally) install [docker engine](https://docs.docker.com/engine/install/).
18+
### Settings file
1819

19-
2- Fork and clone the project.
20+
Copy `example.env` to `.env` and customize it.
2021

21-
3- Inside your project's directory, run `docker compose -f dev-compose.yml up --build` to start building an image.
22+
### Setting up python
2223

23-
4- Test out the webui by accessing http://localhost:8000/
24+
You will need python 3.11+
2425

25-
##### Navigating web UI
26+
<details>
27+
<summary>Extra steps if don't want to install poetry globally for some reason</summary>
2628

27-
Assuming you've managed to get a page running on http://localhost:8000/, we can now start doing things such as registering a test account.
29+
#### Install venv (only first time or after updating sytem python version)
2830

29-
- http://localhost:8000/admin -> Allows you to view all accounts and edit existing ones.
30-
- http://localhost:8000/accounts/register -> Allows you to create an account (if you already don't have one)
31-
- http://localhost:8000/accounts/verify-account -> Allows you to test account verfication manually.
31+
```sh
32+
python -m venv .venv
33+
```
3234

33-
To find more api end points or add new ones, check out `urls.py` under the respective folder of what feature you want mess around with.
35+
#### Activate venv on Linux
36+
37+
```sh
38+
. .venv/bin/activate
39+
```
40+
41+
#### Activate venv on Windows
42+
43+
```bat
44+
.venv\Scripts\activate
45+
```
46+
47+
</details>
48+
49+
#### Dependency installation
50+
51+
Install poetry to manage dependencies and update pip
52+
53+
```sh
54+
pip install -U pip poetry
55+
```
56+
57+
Install dev dependencies
58+
59+
```sh
60+
poetry install
61+
```
3462

63+
#### pre-commit
3564

36-
#### Setting up pre-commit
37-
This repository uses pre-commit hook which runs every time you make a commit to catch linting and formatting errors early.
38-
To enable pre-commit, install it with pip: `pip install -U pre-commit`
39-
After package installation, install hook running `pre-commit install` inside of project directory.
40-
> Hint: if the world is on fire, production servers down, clown hacks your door and you don't have time to make linters happy, you can add `-n` to `git commit` command.
65+
pre-commit is a git hook which runs every time you make a commit to catch linting and formatting errors early.
66+
67+
```sh
68+
pre-commit install
69+
```
70+
71+
> Hint: if the world is on fire, production servers down, clown at your doorstep and you don't have time to make linters happy, add `-n` to `git commit` command (CI will still be mad though).
72+
73+
### Setting up Docker
74+
75+
Docker (with help of compose) lets you launch entire project including database locally without installing anything.
76+
77+
1- To get started with docker, install it from [here](https://docs.docker.com/get-docker/) and (optionally) install [docker engine](https://docs.docker.com/engine/install/).
78+
79+
2- Launch project by running `docker compose -f dev-compose.yml up --build`.
80+
81+
3- Test out the webui by accessing http://localhost:8000/
82+
83+
### Navigating web UI
84+
85+
Assuming you've managed to get a page running on http://localhost:8000/, we can now start doing things such as registering a test account.
86+
87+
- http://localhost:8000/admin -> View all accounts and edit existing ones.
88+
- http://localhost:8000/accounts/register -> Create an account (if you already don't have one)
89+
- http://localhost:8000/accounts/verify-account -> Test account verfication manually.
90+
91+
To find more api end points or add new ones, check out `urls.py` under the respective folder of what feature you want mess around with.

docker-compose.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
version: "3"
22

3-
x-common-volumes: &common-volumes
4-
volumes:
5-
- static-volume:/home/website/statics
6-
- media-volume:/home/website/media
7-
83
services:
94
db:
105
image: postgres:14.1-alpine
@@ -21,7 +16,9 @@ services:
2116
expose:
2217
- 8000
2318
command: gunicorn central_command.wsgi:application --bind 0.0.0.0:8000
24-
<<: *common-volumes
19+
volumes:
20+
- static-volume:/home/website/statics
21+
- media-volume:/home/website/media
2522

2623
volumes:
2724
db-data:

example.env

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
# used for salting
2+
SECRET_KEY=MYSECRET
3+
# django debug mode which prints python traceback in response and more
4+
DEBUG=1
5+
16
EMAIL_HOST=smtp.gmail.com
27
EMAIL_PORT=587
38
EMAIL_HOST_USER=[email protected]
49
EMAIL_HOST_PASSWORD=password
510
EMAIL_PAGE_DOMAIN=http://localhost:8000
6-
SECRET_KEY=MYSECRET
7-
DEBUG=1
11+
812
DB_ENGINE=django.db.backends.postgresql
913
DB_NAME=postgres
1014
DB_HOST=db
11-
DB_PORT=5432
15+
DB_PORT=5432

0 commit comments

Comments
 (0)