python3 -c 'import secrets, base64;print(base64.urlsafe_b64encode(secrets.token_bytes(32)))'
find . | grep -E "(pycache|.pyc|.pyo$)" | xargs rm -rf git add . git commit -m "okay" git push origin master
https://computingforgeeks.com/install-wkhtmltopdf-on-ubuntu-debian-linux/
- apt-get install mysql-server
- setup using - sudo mysql_secure_installation
- create database by executing sql file - mysql -u root -p < testdb2.sql
- Download or clone your project
- inside the project directory create python virtual environment a) python3 -m virtualenv env b) source env/bin/activate
- install all dependencies - pip3 install -r requirements.txt pip3 install 'pydantic[email]' # if required pip3 install 'flask-openapi3[yaml]' # if required
- create service file same as api.service in /etc/systemd/system based on your environment
- start service - systmctl start api.service
- add service to startup - systmctl enable api.service
- check if service is running - systemctl status api.service
- Listen this service to nginx web server a) add a file like "api" in /etc/nginx/sites-available b) Link this file to nginx enable directory - /etc/nginx/sites-enabled sudo ln -s /etc/nginx/sites-available/api /etc/nginx/sites-enabled
- check if service is running or there is no error on deployment - nginx -t
- start nginx web server - systmctl restart nginx
- Run in IP
If you are using cloud server like ubuntu or aws, dont forget to open 80 port or port you required to listen nginx for this api
- Create Dockerfile in app folder
- other project required files
- create a docker-compose.yml in root folder, where you have to execute docker-compose command
- create a nginx.conf file with nginx configuartion to run app in webserver This is important to run app in any webserver so you can execute all running instances in one port with reverse proxy setting This can handle load balancer and traffic
run docker - docker-compose up run with rebuild image - docker-compose up --build run with rebuild image and on background - docker-compose up -d --build run multiple instance of app - docker-compose up -d --build --scale app=3 #3 is for three instance check running instances - docker-compose ps or docker ps stop docker running instances - docker-compose down auto start docker - sudo chkconfig docker on
docker network inspect bridge
sudo su yum update -y amazon-linux-extras install docker systemctl start docker systemctl enable docker usermod -a -G docker ec2-user
docker info
git clone -b master
sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose
export PATH=$PATH:/usr/local/bin/ docker-compose version
docker-compose up -d --build --scale app=5
- Create a new repo in ECR
- Setup IAM role in EC2 instance a. go to IAM role b. create role c. select EC2 d. next go to permission e. select AmazonEC2ContainerRegistryFullAccess f. next go to tag (Optional) g. next go to create role , name the role like docker-ec2-ecr-access-role and Create Role.
- Attach role in EC2 inatance a. select instance in ec2 b. go to action c. modify IAM role
- Setup aws cli and configure aws using command "aws configure"
- run from push command instruction in ECR dashboard Retrieve an authentication token and authenticate your Docker client to your registry. Use the AWS CLI:
=> aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin .dkr.ecr.ap-south-1.amazonaws.com Note: If you receive an error using the AWS CLI, make sure that you have the latest version of the AWS CLI and Docker installed. Build your Docker image using the following command. For information on building a Docker file from scratch see the instructions here . You can skip this step if your image is already built:
=> docker build -t test-docker app/ After the build completes, tag your image so you can push the image to this repository:
=> docker tag test-docker:latest .dkr.ecr.ap-south-1.amazonaws.com/test-docker:latest Run the following command to push this image to your newly created AWS repository:
=> docker push .dkr.ecr.ap-south-1.amazonaws.com/test-docker:latest
- Pull ECR file in EC2 or where you want docker pull .dkr.ecr.ap-south-1.amazonaws.com/test-docker
Change your code as per your requirements and more security to save and pass data while creating send sha256 of password // Example sha256("12345") will be "5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5" { "fullname": "Admin", "username": "admin", "password": sha256(plaintext_password), "email": "admin@gmail.com", "mobile": "12345678" }
same while login { "username": "username/email", "password": "5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5" }