Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .env.backend.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
SECRET_KEY=[SECRET_KEY]

DATABASE_ENGINE=django.db.backends.postgresql_psycopg2
DATABASE_NAME=[DATABASE NAME]
DATABASE_USER=[DATABASE USER]
DATABASE_PASSWORD=[DATABASE PASSWORD]
DATABASE_HOST=[DATABASE HOST]
DATABASE_PORT=[DATABASE PORT]

EMAIL_HOST_USER=[EMAIL HOST USER]
EMAIL_HOST_PASSWORD=[EMAIL HOST PASSWORD]

REDIRECT_URL=[SOME REDIRECT URL]
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Environment files
.env.backend
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "backend"]
path = backend
url = https://github.com/TuiChain/backend
[submodule "frontend"]
path = frontend
url = https://github.com/TuiChain/frontend
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- ----------------------------------------------------------------------- -->

# TuiChain: Deployment

Repository for the deployment of the TuiChain application.

<!-- ----------------------------------------------------------------------- -->

To deploy the TuiChain platform locally, you need to run:

- `cd bin && ./deploy.sh && cd ..`

If you want to delete the containers and the volumes, you need to run:

- `docker-compose down -v`
1 change: 1 addition & 0 deletions backend
Submodule backend added at e52d49
29 changes: 29 additions & 0 deletions bin/backend-docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# pull official base image

FROM python:3.8.3-alpine

# Set work directory
WORKDIR /usr/src/app

# Set environment variables
## Prevents Python from writing pyc files to disk
ENV PYTHONDONTWRITEBYTECODE 1
## Prevents Python from buffering stdout and stderr
ENV PYTHONUNBUFFERED 1

# Install dependencies
RUN pip install --upgrade pip
## Install psycopg2 dependencies
RUN apk update
RUN apk add postgresql-dev gcc python3-dev musl-dev
COPY ./requirements.txt .
RUN pip install -r requirements.txt

# Copy entrypoint.sh
COPY ./entrypoint.sh .

# Copy project
COPY . .

# Run entrypoint.sh
ENTRYPOINT ["/usr/src/app/entrypoint.sh"]
9 changes: 9 additions & 0 deletions bin/backend-docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

while ! nc -z $DATABASE_HOST $DATABASE_PORT; do
sleep 0.1
done

python manage.py migrate

exec "$@"
65 changes: 65 additions & 0 deletions bin/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash

set -e
. "functions.sh"

# ---------------------------------------------------------------------------- #

pp_info "required-tools" "Checking if you have all the required tools"

## docker
if not_installed "docker"; then
pp_error "required-tools" "We are using docker for deploying locally the TuiChain Platform. Pls install it and run this script again."

exit 1
else
pp_success "required-tools" "docker is installed"

if ! docker info > /dev/null 2>&1; then
pp_warn "required-tools" "docker does not seem to be running, run it first and retry"
exit 1
else
pp_success "required-tools" "docker is up-and-running"
fi

fi

## docker-compose
if not_installed "docker-compose"; then

pp_error "required-tools" "We are using docker-compose for deploying locally the TuiChain Platform. Pls install it and run this script again."

exit 1

else

pp_success "required-tools" "docker-compose is installed"

fi

pp_success "required-tools" "All tools are installed"

# ---------------------------------------------------------------------------- #

pp_info "setup" "Setting up the environment"

## backend
cp ./backend-docker/Dockerfile ../backend/Dockerfile
cp ./backend-docker/entrypoint.sh ../backend/entrypoint.sh
pp_success "setup" "Backend needed files copied to backend folder"

## frontend
# cp ./frontend-docker/Dockerfile ../frontend/Dockerfile
# pp_success "setup" "Frontend Dockerfile copied to frontend folder"


# ---------------------------------------------------------------------------- #

pp_info "deployment" "Deploying components in docker"

cd .. && docker-compose up -d --build

pp_success "deployment" "All components are deployed\n\n\tdatabase -> localhost:10000\n\tbackend -> localhost:10001\n"



47 changes: 47 additions & 0 deletions bin/functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

BLUE='\e[34m'
GREEN='\e[32m'
YELLOW='\e[33m'
RED='\e[31m'
RESET='\e[39m'

pp() {
printf "$1[$2]: $3${RESET}\n"
}

pp_info() {
pp $BLUE "$1" "$2"
}

pp_success() {
pp $GREEN "$1" "$2"
}

pp_error() {
pp $RED "$1" "$2"
}

pp_warn() {
pp $YELLOW "$1" "$2"
}

not_installed() {
[ ! -x "$(command -v "$@")" ]
}

ensure_confirmation() {
read -r "confirmation?please confirm you want to continue [y/n] (default: y) "
confirmation=${confirmation:-"y"}

if [ "$confirmation" != "y" ]; then
exit 1
fi
}

ask_confirmation() {
read -r "confirmation?please confirm you want to continue [y/n] (default: y) "
confirmation=${confirmation:-"y"}

[[ "$confirmation" == "y" ]];
}
40 changes: 40 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: '3.7'

services:
database:
image: postgres:latest
container_name: database
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=tuichainDB
- PGDATA=/var/lib/postgresql/data/pgdata
ports:
- 10000:5432
volumes:
- pgdata:/var/lib/postgresql/data
restart: always

backend:
build: ./backend
image: tuichain-backend
container_name: tuichain-backend
environment:
DATABASE_NAME: tuichainDB
DATABASE_USER: postgres
DATABASE_PASSWORD: postgres
DATABASE_HOST: database
DATABASE_PORT: 5432
command: python manage.py runserver 0.0.0.0:8000
volumes:
- ./backend/:/usr/src/app/
ports:
- 10001:8000
env_file:
- ./.env.backend
restart: always
depends_on:
- database

volumes:
pgdata:
1 change: 1 addition & 0 deletions frontend
Submodule frontend added at 1f0e96