Skip to content

Commit

Permalink
bump things and update documentation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Fogapod committed Jan 17, 2024
1 parent f65f4bd commit 217c0b5
Show file tree
Hide file tree
Showing 9 changed files with 243 additions and 210 deletions.
84 changes: 37 additions & 47 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,68 +17,58 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- uses: pre-commit/[email protected]
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- uses: pre-commit/[email protected]

unit_test:
needs: [ lint ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
pip install poetry
poetry config virtualenvs.create false
poetry install
- name: Run tests
env:
SECRET_KEY: secret
DB_ENGINE: django.db.backends.sqlite3
run: |
cd src
python manage.py migrate
python manage.py test tests/
build_docker:
needs: [ lint ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build Docker image
run: |
docker pull $IMAGE_NAME
docker build --pull --cache-from $IMAGE_NAME -t $IMAGE_NAME .
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
pip install poetry
poetry config virtualenvs.create false
poetry install
- name: Run tests
env:
SECRET_KEY: secret
DB_ENGINE: django.db.backends.sqlite3
run: |
cd src
python manage.py migrate
python manage.py test tests/
deploy:
needs: [ unit_test, build_docker ]
if: ${{ github.event_name == 'push' }}
needs: [ lint, unit_test ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v2
- name: Build image
run: |
docker pull $IMAGE_NAME
docker build --pull --cache-from $IMAGE_NAME -t $IMAGE_NAME:latest .
- uses: actions/checkout@v4
- name: Build docker image
run: |
docker pull $IMAGE_NAME
docker build --pull --cache-from $IMAGE_NAME -t $IMAGE_NAME:latest .
- name: Log in into Docker Hub
run: |
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
- name: Log in into Docker Hub
if: ${{ github.event_name == 'push' }}
run: |
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
# Context:
# For some reason, commits from semantic-release bot do not trigger any actions.
# For some reason, commits from semantic-release bot does not trigger any actions.
# Build/push steps were copied into release workflow until we figure out a better way.
# - name: Add a release tag to image
# if: contains(github.ref, 'refs/tags/')
# run: |
# docker tag $IMAGE_NAME $IMAGE_NAME:${GITHUB_REF#refs/tags/}

- name: Push image to registry
run: |
docker push $IMAGE_NAME
- name: Push image to registry
if: ${{ github.event_name == 'push' }}
run: |
docker push $IMAGE_NAME
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
repos:
- repo: https://github.com/ambv/black
rev: 23.3.0
rev: 23.12.1
hooks:
- id: black

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

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -28,6 +28,6 @@ repos:
^.*.md$
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v0.782
# rev: v1.8.0
# hooks:
# - id: mypy
68 changes: 34 additions & 34 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
FROM python:3.10.6-alpine3.16
FROM python:3.11-alpine3.19

# enables proper stdout flushing
ENV PYTHONUNBUFFERED yes
# in order:
# proper stdout flushing for alpine
# no .pyc files
ENV PYTHONDONTWRITEBYTECODE yes

# pip optimizations
ENV PIP_NO_CACHE_DIR yes
ENV PIP_DISABLE_PIP_VERSION_CHECK yes
# do not store pip cache
# do not check pip version
# do not yell about root user
ENV \
PYTHONUNBUFFERED=yes \
PYTHONDONTWRITEBYTECODE=yes \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_ROOT_USER_ACTION=ignore

WORKDIR /src

COPY poetry.lock pyproject.toml ./

RUN apk add --no-cache libpq \
&& apk add --no-cache --virtual .build-deps \
# https://cryptography.io/en/latest/installation/#alpine
gcc \
musl-dev \
python3-dev \
libffi-dev \
openssl-dev \
cargo \
postgresql-dev \
COPY poetry.lock pyproject.toml .

RUN : \
# psycopg runtime dep
&& apk add --no-cache libpq \
&& pip install poetry \
&& poetry config virtualenvs.create false \
&& poetry install --no-dev \
&& apk del --purge .build-deps
&& poetry install --only main

COPY src .

RUN mkdir /home/website
RUN mkdir /home/website/statics
RUN mkdir /home/website/media

# I'm too dumb to make user permissions over shared volumes work
#RUN addgroup -S unitystation \
# && adduser -S central_command -G unitystation \
# && chown -R central_command:unitystation /src \
# && chown -R central_command:unitystation $home
# RUN : \
# && addgroup -S unitystation \
# && adduser -S central_command -G unitystation \
# && chown -R central_command:unitystation /src
#
#USER central_command
# USER central_command

RUN : \
&& mkdir /home/website \
&& mkdir /home/website/statics \
&& mkdir /home/website/media

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

ENTRYPOINT ["./entrypoint.sh"]
ENTRYPOINT ["./entrypoint.sh"]
76 changes: 56 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,76 @@
# Central Command

![Docker Image Version (latest by date)](https://img.shields.io/docker/v/unitystation/central-command?sort=date)
[![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)

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

### Features
- Account managment and user validation.
- Server list managment.
## Features

- Account management and user validation.
- Server list management.
- In-game persistence.
- Works cross-fork!
- Modular architecture.

### Development guide
#### Setting up Docker
## Development guide

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/).
### Setting up python

2- Fork and clone the project.
You will need python 3.11+

3- Inside your project's directory, run `docker compose -f dev-compose.yml up --build` to start building an image.
#### Install venv (only first time or after updating sytem python version)

4- Test out the webui by accessing http://localhost:8000/
```sh
python -m venv .venv
```

##### Navigating web UI
#### Activate venv on Linux

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.
```sh
. .venv/bin/activate
```

- http://localhost:8000/admin -> Allows you to view all accounts and edit existing ones.
- http://localhost:8000/accounts/register -> Allows you to create an account (if you already don't have one)
- http://localhost:8000/accounts/verify-account -> Allows you to test account verfication manually.
#### Activate venv on Windows

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.
```bat
.venv\Scripts\activate
```

#### Dependency installation

Install poetry to manage dependencies and update pip

```sh
pip install -U pip poetry
```

#### pre-commit

pre-commit is a git hook which runs every time you make a commit to catch linting and formatting errors early.

```sh
pre-commit install
```

> 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).
#### Setting up pre-commit
This repository uses pre-commit hook which runs every time you make a commit to catch linting and formatting errors early.
To enable pre-commit, install it with pip: `pip install -U pre-commit`
After package installation, install hook running `pre-commit install` inside of project directory.
> 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.
### Setting up Docker

Docker (with help of compose) lets you launch entire project including database locally without installing anything.

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/).

2- Launch project by running `docker compose -f dev-compose.yml up --build`.

3- Test out the webui by accessing http://localhost:8000/

### Navigating web UI

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.

- http://localhost:8000/admin -> View all accounts and edit existing ones.
- http://localhost:8000/accounts/register -> Create an account (if you already don't have one)
- http://localhost:8000/accounts/verify-account -> Test account verfication manually.

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.
9 changes: 3 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
version: "3"

x-common-volumes: &common-volumes
volumes:
- static-volume:/home/website/statics
- media-volume:/home/website/media

services:
db:
image: postgres:14.1-alpine
Expand All @@ -21,7 +16,9 @@ services:
expose:
- 8000
command: gunicorn central_command.wsgi:application --bind 0.0.0.0:8000
<<: *common-volumes
volumes:
- static-volume:/home/website/statics
- media-volume:/home/website/media

volumes:
db-data:
Expand Down
10 changes: 7 additions & 3 deletions example.env
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# used for salting
SECRET_KEY=MYSECRET
# django debug mode which prints python traceback in response and more
DEBUG=1

EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_HOST_USER=[email protected]
EMAIL_HOST_PASSWORD=password
EMAIL_PAGE_DOMAIN=http://localhost:8000
SECRET_KEY=MYSECRET
DEBUG=1

DB_ENGINE=django.db.backends.postgresql
DB_NAME=postgres
DB_HOST=db
DB_PORT=5432
DB_PORT=5432
Loading

0 comments on commit 217c0b5

Please sign in to comment.