Skip to content

Commit b858b5a

Browse files
926 migrate beta deploy to use ghcr instead of docker hub 2 (#945)
* Adding distinct github image deployable. * Creating a dockerignore to avoid files too big. * Adjusting dockerfile to only consume the minimal fields. * Bonus quicksetup fix, for speedup. Migrations should be made at build time. * Adding in a sqlite change or two for speedup.
1 parent 5bbfcda commit b858b5a

6 files changed

Lines changed: 63 additions & 9 deletions

File tree

.dockerignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.git
2+
__pycache__
3+
*.pyc
4+
*.pyo
5+
.venv
6+
.env
7+
*.sqlite3
8+
.github
9+
.gitignore
10+
README.md
11+
CONTRIBUTING.md
12+
CODE_OF_CONDUCT.md
13+
LICENSE
14+
*.md
15+
.pytest_cache
16+
.ruff_cache
17+
node_modules

.github/workflows/build_and_deploy.yml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ on:
44
branches:
55
- staging
66
- main
7+
paths-ignore:
8+
- 'README.md'
9+
- 'docs/**'
10+
- 'scripts/**'
11+
- '.github/ISSUE_TEMPLATE/**'
12+
13+
concurrency:
14+
group: deploy-${{ github.ref_name }}
15+
cancel-in-progress: true
716

817
jobs:
918
build:
@@ -14,21 +23,32 @@ jobs:
1423
with:
1524
username: ${{ secrets.DOCKERHUB_USERNAME }}
1625
password: ${{ secrets.DOCKERHUB_TOKEN }}
17-
- name: Set Docker image tag
18-
run: |
26+
- name: Login to GHCR
27+
uses: docker/login-action@v2
28+
with:
29+
registry: ghcr.io
30+
username: ${{ github.actor }}
31+
password: ${{ secrets.GITHUB_TOKEN }}
32+
- name: Set image tags
33+
run: |
1934
echo "GITHUB_REF = $GITHUB_REF" > version.py
2035
echo "GITHUB_SHA = $GITHUB_SHA" >> version.py
21-
36+
2237
if [[ $GITHUB_REF == refs/heads/main ]]; then
23-
echo "DOCKER_IMAGE_TAG=latest" >> $GITHUB_ENV
38+
echo "IMAGE_TAGS=eepmoody/open5e-api:latest" >> $GITHUB_ENV
2439
elif [[ $GITHUB_REF == refs/heads/staging ]]; then
25-
echo "DOCKER_IMAGE_TAG=staging" >> $GITHUB_ENV
40+
{
41+
echo "IMAGE_TAGS<<EOF"
42+
echo "eepmoody/open5e-api:staging"
43+
echo "ghcr.io/open5e/open5e-api:beta"
44+
echo "EOF"
45+
} >> $GITHUB_ENV
2646
fi
2747
- name: Build and push
2848
uses: docker/build-push-action@v7
2949
with:
3050
push: true
31-
tags: eepmoody/open5e-api:${{ env.DOCKER_IMAGE_TAG }}
51+
tags: ${{ env.IMAGE_TAGS }}
3252

3353
deploy:
3454
runs-on: ubuntu-latest

.github/workflows/pr_validation.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
run: uv python install 3.11
2222
- name: Install dependencies
2323
run: uv sync
24+
- name: Check migrations are up to date
25+
run: uv run python manage.py makemigrations --check --dry-run
2426
- name: Run migrations
2527
run: uv run python manage.py quicksetup --noindex
2628
- name: Run Tests

Dockerfile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@ FROM python:3.11-slim
1414

1515
WORKDIR /opt/services/open5e-api
1616

17-
COPY --from=builder /build/.venv /opt/services/open5e-api/.venv
18-
COPY --from=builder /build /opt/services/open5e-api
17+
COPY --from=builder /build/.venv ./.venv
18+
COPY --from=builder /build/server ./server
19+
COPY --from=builder /build/api ./api
20+
COPY --from=builder /build/api_v2 ./api_v2
21+
COPY --from=builder /build/search ./search
22+
COPY --from=builder /build/templates ./templates
23+
COPY --from=builder /build/staticfiles ./staticfiles
24+
COPY --from=builder /build/db.sqlite3 ./db.sqlite3
25+
COPY --from=builder /build/manage.py ./manage.py
26+
COPY --from=builder /build/newrelic.ini ./newrelic.ini
1927

2028
ENV PATH="/opt/services/open5e-api/.venv/bin:$PATH"
2129

api/management/commands/quicksetup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ def migrate_db() -> None:
9494
This command is added primarily to assist in local development, because
9595
checking out and changing branches results in unclean model/dbs."""
9696

97-
call_command('makemigrations')
9897
call_command('migrate')
9998

10099
def is_dirty() ->None:

server/settings.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@
121121
"default": {
122122
"ENGINE": "django.db.backends.sqlite3",
123123
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
124+
"OPTIONS": {
125+
"init_command": (
126+
"PRAGMA journal_mode=WAL;"
127+
"PRAGMA synchronous=NORMAL;"
128+
"PRAGMA cache_size=-65536;"
129+
"PRAGMA temp_store=MEMORY;"
130+
),
131+
},
124132
}
125133
}
126134

0 commit comments

Comments
 (0)