This repository is for CleanApp (http://cleanapp.io) backend development.
There are three environments:
local
- a local machine outside clouddev
- development machine in cloudprod
- production machine in cloud
- Make sure that your local machine has Docker installed. https://docs.docker.com/engine/install/
- Make sure you're prepared for working with GoogleCloud.
- You got necessary access to Google Cloud services. Ask project admins for them.
- You have gcloud command line interface installed, https://cloud.google.com/sdk/docs/install
- You are successfully logged in gcloud, https://cloud.google.com/sdk/gcloud/reference/auth/login
- Build docker images on your local machine.
- Deploy services on the cloud or local machine.
- Modify the Docker image version if necessary. Open the file
docker_backend/.version
and set the desired value of theBUILD_VERSION
. - Run the
docker_backend/build_server_image.sh
from thedocker_backens
directory.cd docker_backend && ./build_image.sh
- Modify the Docker image version if necessary. Open the file
docker_pipelines/.version
and set the desired value of theBUILD_VERSION
. - Run the
docker_backend/build_server_image.sh
from thedocker_pipelines
directory.cd docker_pipelines && ./build_image.sh
The deploying process includes:
- pulling docker images and running four services:
- cleanapp backend service;
- cleanapp referral service;
- mysql database;
- cleanapp web service;
- adding Google cloud scheduler for following processes:
- referrals redeem;
- tokens disbursement;
Pre-requisites
- Linux (Debian/Ubuntu/...), this is tested on Google Cloud Ubuntu VPS instance.
- Make sure that gcloud is present on the cloud machine. It should be pre-installed by google cloud.
- for installing on your local machine make sure that you installed gcloud.
- Login to the target machine.
- On GCloud you go to the dashboard, pick the instance, and the click on SSH
- Get setup.sh into the current directory, e.g. using
curl https://raw.githubusercontent.com/cleanappio/cleanapp_back_end_v2/main/setup/setup.sh > setup.sh &&
sudo chmod a+x setup.sh
- Run
./setup.sh
It should be up and running now.
- Stopping:
./down.sh
- Restarting after a stop:
./up.sh
- Stopping with deletion of the database:
sudo docker-compose down -v
- Refreshing images to the newly built versions:
- Stop services
- Delete loaded images (
docker images
anddocker image
commands, you may need to use -f flag) - If you need a different label or prefix, edit
docker-compose.yaml
file. - (preferable) Load new images using
sudo docker pull
command - Restart services.
- API server exposes port 8080.
- APP server exposes port 3000.
- MySQL DB uses port 3306 but currently does not expose it externally. Do so, if you want to connect to it from outside.
Caveat: Google Cloud UI is not stable, so the instruction below may become obsolete. This is the status on January 2024.
On the account level you need to create firewall rules "allow-8080" and "allow-3000"
Dashboard -> VPC Network -> Firewall, look at VPC Firewall Rules.
It will have the list of available rules. On top of the page (!Not near the table!) there will be a button "Create Firewall Rule"
- Name: allow-8080
- Description: Allow port 8080.
- Target tags: allow-8080
- Source filters, IP ranges: 0.0.0.0/0
- Protocols and ports: tcp:8080
- It's ok to leaave the rest default.
Create another rule for port 3000 using the same way.
You are almost done. Now in Compute Engine > VM Instances select the one you want to use. Pick Edit at the top. Go to network tags and add "allow-8080" and "allow-3000". Save.
You are ready to deploy on this VM.
From outside try:
- http://dev.api.cleanapp.io:8080/help
- http://dev.api.cleanapp.io:8090/help
- http://dev.app.cleanapp.io:3000/help
Both times you will get a plain short welcome message with CleanApp API/APP version. Remove dev.
prefix for prod instance.
We picked
- E2 Low cost, day-to-day computing
- US-Central1 Iowa
- e2-medium (2 vCPU, 1 core, 4 GB memory)
- 10Gb Disk
- ubuntu-2004-focal-v20231101 *Canonical, Ubuntu, 20.04 LTS, amd64 focal image built on 2023-11-01
- HTTP/HTTPS allowed.
Currently we have three secrets per environment:
- MYSQL_APP_PASSWORD_<env>
- MYSQL_READER_PASSWORD_<env>
- MYSQL_ROOT_PASSWORD_<env>
where <env> is
LOCAL
,DEV
orPROD
.
- cleanapp-1 Dev instance, http://dev.api.cleanapp.io / http://dev.app.cleanapp.io point to this instance (external IP 34.132.121.53).
- cleanapp-prod Prod instance, http://api.cleanapp.io / http://app.cleanapp.io point to this instance (TODO: Create the machine and edit DNS)
More infro is to be added.