Skip to content

Commit 25f2b08

Browse files
committed
Merge branch 'development_1.1' into development_2.0.0
2 parents 0d28630 + d9ac12e commit 25f2b08

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+703
-277
lines changed

.github/workflows/django.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ jobs:
2222
echo DJANGO_SECRET_KEY=${{ secrets.DJANGO_SECRET_KEY }} >> .env
2323
echo DJANGO_DEBUG=${{ secrets.DJANGO_DEBUG }} >> .env
2424
echo EMAIL=${{ secrets.EMAIL }} >> .env
25-
echo EPASSWORD=${{ secrets.EPASSWORD }} >> .env
25+
echo EMAIL_PASSWORD=${{ secrets.EMAIL_PASSWORD }} >> .env
2626
echo EMAIL_HOST=${{ secrets.EMAIL_HOST }} >> .env
27+
echo ENV=${{ secrets.EMAIL_HOST }} >> .env
28+
echo SERVER_DOMAIN_NAME=${{ secrets.SERVER_DOMAIN_NAME }} >> .env
29+
echo CLIENT_DOMAIN_NAME=${{ secrets.CLIENT_DOMAIN_NAME }} >> .env
30+
2731
cat .env
2832
- name: Set up Python ${{ matrix.python-version }}
2933
uses: actions/setup-python@v3
@@ -33,7 +37,4 @@ jobs:
3337
run: |
3438
python -m pip install --upgrade pip
3539
pip install poetry
36-
poetry install
37-
- name: Run Tests
38-
run: |
39-
poetry run python manage.py test
40+
cd server && poetry install

Dockerfile

Lines changed: 0 additions & 36 deletions
This file was deleted.

Makefile

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,64 @@
1+
12
CMD:=poetry run
2-
client=cd client
3-
up:
4-
docker-compose up --build -d
3+
client:=cd client
4+
server:=cd server
5+
6+
help:
7+
@echo "\n- Docker: To build and run a specific service, you can do that by executing 'make docker-up service=<service_name>'."
8+
@echo "\n- To run a the backend project, you can do that by executing 'make runserver'."
9+
@echo "\n- To run a the backend client, you can do that by executing 'make runclient'."
10+
11+
docker-up:
12+
ifeq ($(service), frontend)
13+
docker compose -f ./docker/docker-compose.yml --env-file=./config/.env up frontend --build -d
14+
else ifeq ($(service), backend)
15+
docker compose -f ./docker/docker-compose.yml --env-file=./config/.env up backend --build -d
16+
else ifeq ($(service), postgres)
17+
docker compose -f ./docker/docker-compose.yml --env-file=./config/.env up postgres --build -d
18+
else
19+
docker compose -f ./docker/docker-compose.yml --env-file=./config/.env up --build -d
20+
endif
21+
22+
docker-down:
23+
ifeq ($(service), frontend)
24+
docker compose -f ./docker/docker-compose.yml --env-file=./config/.env down frontend
25+
else ifeq ($(service), backend)
26+
docker compose -f ./docker/docker-compose.yml --env-file=./config/.env down backend
27+
else ifeq ($(service), postgres)
28+
docker compose -f ./docker/docker-compose.yml --env-file=./config/.env down postgres
29+
else
30+
docker compose -f ./docker/docker-compose.yml --env-file=./config/.env down
31+
endif
32+
33+
docker-logs:
34+
ifeq ($(service), frontend)
35+
docker compose -f ./docker/docker-compose.yml --env-file=./config/.env logs -f frontend
36+
else ifeq ($(service), backend)
37+
docker compose -f ./docker/docker-compose.yml --env-file=./config/.env logs -f backend
38+
else ifeq ($(service), postgres)
39+
docker compose -f ./docker/docker-compose.yml --env-file=./config/.env logs -f postgres
40+
else
41+
docker compose -f ./docker/docker-compose.yml --env-file=./config/.env logs -f
42+
endif
43+
544
install:
6-
curl -sSL https://install.python-poetry.org | python3 -
7-
poetry install
8-
poetry check
45+
$(server) && poetry install
46+
$(server) && poetry check
47+
$(client) && yarn
948
runserver:
10-
$(CMD) python3 manage.py runserver
49+
$(server) && $(CMD) python3 manage.py runserver
1150
runclient:
12-
$(client) && npm install && npm run dev
51+
$(client) && yarn && yarn dev
1352
test:
14-
$(CMD) python3 manage.py test
53+
$(server) && $(CMD) python3 manage.py test
1554
lint:
16-
$(CMD) black .
17-
$(CMD) flake8 . --exclude=__init__.py
55+
$(server) && $(CMD) black . --exclude=__init__.py
56+
$(server) && $(CMD) flake8 . --exclude=__init__.py
57+
$(client) && yarn lint
1858
migrate:
19-
$(CMD) python3 manage.py migrate
20-
migrations:
21-
$(CMD) python3 manage.py makemigrations
59+
$(server) && $(CMD) python3 manage.py makemigrations
60+
$(server) && $(CMD) python3 manage.py migrate
2261
user:
23-
$(CMD) python3 manage.py createsuperuser
24-
$(CMD) python3 manage.py sqlmigrate test_tracker 0006
62+
$(server) && $(CMD) python3 manage.py createsuperuser
63+
data:
64+
$(server) && $(CMD) python3 manage.py create locations users

config/.env.template

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,35 @@
44
# Template files must be committed to the VCS, but must not contain
55
# any secret values.
66

7-
7+
# Backend configurations
88
# === Django ===
99
# Generate yours with:
1010
# python3 -c 'from django.utils.crypto import get_random_string; print(get_random_string(50))'
11-
1211
DJANGO_SECRET_KEY=<DJANGO_SECRET_KEY>
12+
# --- > Change to ON when you on local machine OFF when you are on production
13+
DJANGO_DEBUG=ON # Keep it on.
14+
# ---> Mail service configurations
15+
EMAIL=<EMAIL>
16+
EMAIL_PASSWORD=<EMAIL_PASSWORD>
17+
EMAIL_HOST=<EMAIL_HOST>
1318

14-
# Change to ON when you on local machine
15-
DJANGO_DEBUG=OFF
1619

17-
# === Email ===
18-
EMAIL=<EMAIL>
19-
EPASSWORD=<EMAIL_PASSWORD>
20-
EMAIL_HOST=<EMAIL_HOST>
20+
# Servers configurations
21+
CLIENT_DOMAIN_NAME=<CLIENT_DOMAIN_NAME>
22+
SERVER_DOMAIN_NAME=<SERVER_DOMAIN_NAME>
23+
SERVER_DOMAIN_NAME_API=<SERVER_DOMAIN_NAME_API>
24+
25+
DJANGO_SUPERUSER_EMAIL=<DJANGO_SUPERUSER_EMAIL>
26+
DJANGO_SUPERUSER_PASSWORD=<DJANGO_SUPERUSER_PASSWORD>
27+
28+
# Database configurations
29+
# ---> Postgres
30+
DATABASE_NAME=<DATABASE_NAME>
31+
DATABASE_USER=<DATABASE_USER>
32+
DATABASE_PASSWORD=<DATABASE_PASSWORD>
33+
DATABASE_HOST=<DATABASE_HOST>
34+
DATABASE_PORT=<DATABASE_PORT>
35+
36+
# Development ---> To use the development version e.g. sqlite database.
37+
# Production ---> To use the development version e.g. postgres database.
38+
ENV="production | development"

docker-compose.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

docker/backend.Dockerfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
FROM ubuntu:22.04
2+
3+
# Set the environment variable
4+
ENV DEBIAN_FRONTEND=noninteractive TZ=Etc/UTC
5+
ENV REDIS_HOST=$REDIS_HOST
6+
ENV DJANGO_DEBUG=$DJANGO_DEBUG
7+
ENV EMAIL=$EMAIL
8+
ENV EMAIL_PASSWORD=$EMAIL_PASSWORD
9+
ENV EMAIL_HOST=$EMAIL_HOST
10+
ENV DJANGO_SUPERUSER_EMAIL=$DJANGO_SUPERUSER_EMAIL
11+
ENV DJANGO_SUPERUSER_PASSWORD=$DJANGO_SUPERUSER_PASSWORD
12+
ENV SERVER_DOMAIN_NAME=$SERVER_DOMAIN_NAME
13+
ENV CLIENT_DOMAIN_NAME=$CLIENT_DOMAIN_NAME
14+
ENV ENV=$ENV
15+
ENV DATABASE_NAME=$DATABASE_NAME
16+
ENV DATABASE_USER=$DATABASE_USER
17+
ENV DATABASE_PASSWORD=$DATABASE_PASSWORD
18+
ENV DATABASE_HOST=$DATABASE_HOST
19+
ENV DATABASE_PORT=$DATABASE_PORT
20+
21+
RUN echo deb http://be.archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse >> /etc/apt/sources.list
22+
RUN apt-get -y update && \
23+
apt-get -y install wget sudo netcat redis vim python3.8 python3-pip && \
24+
rm -rf /var/lib/apt/lists/*
25+
26+
WORKDIR /server
27+
28+
RUN wget -O /sbin/zinit https://github.com/threefoldtech/zinit/releases/download/v0.2.5/zinit && \
29+
chmod +x /sbin/zinit && pip install poetry && poetry --version
30+
31+
RUN mkdir -p /etc/zinit/
32+
33+
COPY ./server /server
34+
COPY ./docker/scripts/backend/zinit /etc/zinit
35+
COPY ./docker/scripts/backend/*.sh /server/scripts/
36+
COPY ./config /config/
37+
38+
RUN chmod +x /server/scripts/*.sh
39+
40+
EXPOSE 8000
41+
ENTRYPOINT ["zinit", "init"]

docker/configuration.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Runing the project using Docker and Docker Compose
2+
3+
To run the full project with all instances, follow these steps:
4+
5+
1. Set Environment Variables
6+
7+
Create a `.env` file beside the [config](.././config/) directory and set the necessary environment variables. Refer to the previous section for sample environment variable configurations.
8+
9+
2. Execute Docker Compose
10+
11+
Run the following command to start the Docker containers:
12+
13+
```sh
14+
# --> To run all services
15+
16+
└─(✹)──> docker compose -f ./docker/docker-compose.yml --env-file=./config/.env up --build -d
17+
18+
# --> To stop all services
19+
└─(✹)──> docker compose -f ./docker/docker-compose.yml --env-file=./config/.env down
20+
21+
```
22+
23+
Also, you can excute the command using Make:
24+
25+
- make docker-up **To run all services**
26+
- make docker-down **To stop all services**
27+
28+
After executing the command, you should see a confirmation similar to the following:
29+
30+
3. Verify Successful Deployment
31+
32+
This indicates that the Docker containers are being created and the services are starting up.

docker/docker-compose.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
version: "3"
2+
3+
services:
4+
postgres_db:
5+
image: postgres:latest
6+
container_name: postgres_db
7+
ports:
8+
- "5432:5432"
9+
environment:
10+
- POSTGRES_DB=${DATABASE_NAME}
11+
- POSTGRES_USER=${DATABASE_USER}
12+
- POSTGRES_PASSWORD=${DATABASE_PASSWORD}
13+
restart: always
14+
volumes:
15+
- postgres_data:/var/lib/postgresql/data
16+
networks:
17+
- test_tracker-network
18+
19+
backend:
20+
build:
21+
context: ../
22+
dockerfile: ./docker/backend.Dockerfile
23+
container_name: test_tracker-backend
24+
ports:
25+
- "8000:8000"
26+
environment:
27+
# Backend configurations
28+
- ENV=${ENV}
29+
- DJANGO_DEBUG=${DJANGO_DEBUG}
30+
- DJANGO_SUPERUSER_EMAIL=${DJANGO_SUPERUSER_EMAIL}
31+
- DJANGO_SUPERUSER_PASSWORD=${DJANGO_SUPERUSER_PASSWORD}
32+
# Mail service configurations
33+
- EMAIL=${EMAIL}
34+
- EMAIL_PASSWORD=${EMAIL_PASSWORD}
35+
- EMAIL_HOST=${EMAIL_HOST}
36+
# Servers configurations
37+
- SERVER_DOMAIN_NAME=${SERVER_DOMAIN_NAME}
38+
- CLIENT_DOMAIN_NAME=${CLIENT_DOMAIN_NAME}
39+
# Database configurations
40+
- DATABASE_NAME=${DATABASE_NAME}
41+
- DATABASE_USER=${DATABASE_USER}
42+
- DATABASE_PASSWORD=${DATABASE_PASSWORD}
43+
- DATABASE_PORT=${DATABASE_PORT}
44+
- DATABASE_HOST=postgres_db
45+
depends_on:
46+
- postgres_db
47+
volumes:
48+
- backend_media:/server/mediafiles/profile_image
49+
networks:
50+
- test_tracker-network
51+
52+
frontend:
53+
build:
54+
context: ../
55+
dockerfile: ./docker/frontend.Dockerfile
56+
container_name: test_tracker-frontend
57+
ports:
58+
- "8080:8080"
59+
environment:
60+
- SERVER_DOMAIN_NAME_API=${SERVER_DOMAIN_NAME_API}
61+
depends_on:
62+
- backend
63+
networks:
64+
- test_tracker-network
65+
66+
volumes:
67+
postgres_data:
68+
backend_media:
69+
70+
networks:
71+
test_tracker-network:
72+
backend_media:

docker/frontend.Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# build stage
2+
FROM node:18.18.2 as build-stage
3+
WORKDIR /client
4+
5+
ENV SERVER_DOMAIN_NAME_API=$SERVER_DOMAIN_NAME_API
6+
7+
# Copy package.json and package-lock.json separately to leverage Docker cache
8+
COPY ./client/package*.json /client
9+
COPY ./docker/scripts/frontend/build-env.sh /client/scripts/
10+
11+
RUN npm i -g pnpm && pnpm install
12+
RUN chmod +x /client/scripts/build-env.sh
13+
COPY ./client /client
14+
RUN pnpm build
15+
16+
FROM nginx:stable-alpine as production-stage
17+
COPY ./nginx/prod.conf /temp/prod.conf
18+
19+
RUN envsubst '$SERVER_DOMAIN_NAME_API' < /temp/prod.conf > /etc/nginx/conf.d/default.conf
20+
21+
# Copy the build artifacts and build-env.sh from the build-stage
22+
COPY --from=build-stage /client/dist /usr/share/nginx/html
23+
COPY --from=build-stage /client/scripts/build-env.sh /usr/share/nginx/html
24+
25+
EXPOSE 80
26+
27+
CMD ["/bin/sh", "-c", "/usr/share/nginx/html/build-env.sh && nginx -g \"daemon off;\""]

0 commit comments

Comments
 (0)