Skip to content

Commit d429d80

Browse files
committed
Moved API deployment to fly.io
1 parent a495f89 commit d429d80

File tree

5 files changed

+80
-8
lines changed

5 files changed

+80
-8
lines changed

.dockerignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ db.sqlite3
99
static
1010
.env
1111
.venv/
12-
.coverage
12+
.coverage
13+
fly.toml

.github/workflows/fly-deploy.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/
2+
3+
name: Fly Deploy
4+
on:
5+
push:
6+
branches:
7+
- main
8+
jobs:
9+
deploy:
10+
name: Deploy app
11+
runs-on: ubuntu-latest
12+
concurrency: deploy-group # optional: ensure only one action runs at a time
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: superfly/flyctl-actions/setup-flyctl@master
16+
- run: flyctl deploy --remote-only
17+
env:
18+
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

Dockerfile

+25-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
1-
FROM python:3.11.4-slim-buster
1+
ARG PYTHON_VERSION=3.11-slim
2+
3+
FROM python:${PYTHON_VERSION}
24

35
ENV PYTHONDONTWRITEBYTECODE 1
46
ENV PYTHONUNBUFFERED 1
57

6-
WORKDIR /app
8+
# install psycopg2 dependencies.
9+
RUN apt-get update && apt-get install -y \
10+
libpq-dev \
11+
gcc \
12+
&& rm -rf /var/lib/apt/lists/*
13+
14+
RUN mkdir -p /code
15+
16+
WORKDIR /code
17+
18+
COPY requirements.txt /tmp/requirements.txt
19+
20+
# install psycopg2 dependencies.
21+
RUN set -ex && \
22+
pip install --upgrade pip && \
23+
pip install -r /tmp/requirements.txt && \
24+
rm -rf /root/.cache/
25+
COPY . /code
726

8-
COPY . .
27+
# env var for building purposes
28+
ENV SECRET_KEY "aGkCk2XY3qk7kOZ0HDXoGq5DXlshIhfpspT2bgrV13CzJWCsQa"
929

10-
RUN pip install --upgrade pip && \
11-
pip install --no-cache-dir -r requirements.txt
30+
RUN python manage.py collectstatic --noinput
1231

1332
EXPOSE 8000
1433

15-
CMD ["gunicorn", "--reload", "--bind", ":8000", "--workers", "2", "minesweeper.wsgi"]
34+
CMD ["gunicorn","--bind",":8000","--workers","2","minesweeper.wsgi"]

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This repo contains the backend code built using Python/Django for the Minesweepe
55
The Frontend is built with React and the code is available at [Minesweeper API](https://github.com/fnscoder/minesweeper-web)
66

77
You can check the live game here: [Minesweeper](https://minesweeper-web-eight.vercel.app/)
8+
API is available here: [Minesweeper API](https://minesweeper-api.fly.dev/api/)
89

910
## How to run the project with docker
1011

@@ -40,7 +41,7 @@ You can check the live game here: [Minesweeper](https://minesweeper-web-eight.ve
4041
* Docker Compose
4142
* RUFF
4243
* Gunicorn
43-
* Running on Render
44+
* Running on fly.io
4445

4546
## API Endpoints
4647
* GET `/api/games/`: List all games

fly.toml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# fly.toml app configuration file generated for minesweeper-api on 2024-11-22T09:15:04-03:00
2+
#
3+
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
4+
#
5+
6+
app = 'minesweeper-api'
7+
primary_region = 'yyz'
8+
console_command = '/code/manage.py shell'
9+
10+
[build]
11+
12+
[deploy]
13+
release_command = 'python manage.py migrate --noinput'
14+
15+
[env]
16+
PORT = '8000'
17+
18+
[http_service]
19+
internal_port = 8000
20+
force_https = true
21+
auto_stop_machines = 'stop'
22+
auto_start_machines = true
23+
min_machines_running = 0
24+
processes = ['app']
25+
26+
[[vm]]
27+
memory = '1gb'
28+
cpu_kind = 'shared'
29+
cpus = 1
30+
31+
[[statics]]
32+
guest_path = '/code/static'
33+
url_prefix = '/static/'

0 commit comments

Comments
 (0)