- vừa được xem lúc

How to deploy Amplication app to DigitalOcean

0 0 38

Người đăng: Thuc Pham Ngoc

Theo Viblo Asia

This article shows you the way to deploy an app generated by Amplication to DigitalOcean. Amplication provides the dockerfile to use containers for deployment, but this blog explains how to do it manually. I will guide you step by step to deploy Nestjs app and Postgres database with DOCKER, NGINX and PM2.

1. Sign up a Digital Ocean account

2. Create a droplet

  • Click on "Create" button and select create droplet
  • Config your droplet (CPU, region, ssh,...) image
  • Waiting for your machine initialization image
  • After finish loading, go to tab "Access", you will see a button to load the console. image

3. Install Nodejs, NPM

sudo apt update
sudo apt install nodejs
sudo apt install npm

4. Install Docker

  • Install HTTPS packages:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
  • Add the GPG key to your system:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  • Add repository to APT sources:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
  • Install Docker:
sudo apt install docker-ce
  • Finally, Install Docker Compose:
sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

5. Clone project from your git repository

git clone https://github.com/<username>/<repo-name>.git

If you don't see your code, please checkout this document on how to sync your code from Amplication to GitHub https://docs.amplication.com/docs/sync-with-github You can also use my repo for testing: https://github.com/thucpn/amplication-server-demo-deploy

6. Install dependencies and initialize database

  • Go to server folder and install dependencies
cd <your-repo>/server
npm install
  • Generate Prisma client
npm run prisma:generate
  • Start database in Docker
npm run docker:db
  • Initiate the database
npm run db:init
  • Start the server
npm start

Go to <droplet-ip-address>:3000 (example: 159.65.6.71:3000), you will see the response from server.

7. Setup PM2 to manage process

  • Install PM2
sudo npm i pm2 -g
  • Create an app
pm2 start dist/main.js --name myserver

Your app is now running! image

  • View logs of app
pm2 logs myserver

8. Setup ufw firewall

sudo ufw enable
sudo ufw status
sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https

9. Setup NGINX as a reverse proxy

  • Install nginx
sudo apt install nginx
  • Open config file
sudo nano /etc/nginx/sites-available/default
  • Add the following to location block
 location / { proxy_pass http://localhost:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; }
  • Check NGINX config correctly
sudo nginx -t
  • Restart NGINX
sudo service nginx restart

Visit <droplet-ip-address> (example: 159.65.6.71), you will see app running without port. That's awesome!

10. Here's my result

References:

These are the sources that I have consulted:

https://docs.amplication.com/docs/ https://pm2.keymetrics.io/docs/usage/process-management/ https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-18-04 https://www.digitalocean.com/community/tutorials/how-to-install-docker-compose-on-ubuntu-18-04 https://medium.com/swlh/deploy-nest-js-app-with-postgres-in-vps-e1ce4abd2cad https://gist.github.com/bradtraversy/cd90d1ed3c462fe3bddd11bf8953a896

Bình luận

Bài viết tương tự

- vừa được xem lúc

Deploy app Laravel App lên Heroku có kết nối Database

Trong bài hôm nay, thì mình sẽ giới thiệu cho các bạn cách để deploy một app Laravel lên Heroku bằng git và Heroku CLI. Heroku là nền tảng đám mây cho phép các lập trình viên xây dựng, triển khai, quản lý và mở rộng ứng dụng, nó rất linh hoạt và dễ sử dụng, cung cấp cho một con đường đơn giản nhất đ

0 0 48

- vừa được xem lúc

Những việc cần làm khi deploy một Rails app sử dụng Docker và CircleCI

Bài viết gốc: dnlblog.com. Khi bạn sử dụng docker cho ứng dụng của mình, việc deploy trở nên đơn giản hơn rất nhiều. Nếu bạn kết hợp với CircleCI nữa thì mọi thứ còn tuyệt vời hơn nữa.

0 0 22

- vừa được xem lúc

Deploy application Machine Learning into Cloud Foundry by Docker

Chào mọi người, nội dung của blog nói về việc deploy một ứng dụng Machine Learning lên Cloud Foundry bằng Docker. Tổng quan một số khái niệm cơ bản:.

0 0 37

- vừa được xem lúc

How to Deploy React App to GitHub Pages | Hosting a React App for Free using Github Pages

How to Deploy React App to GitHub Pages | Hosting a React App for Free using Github Pages. . In this video, we will Deploy React App to GitHub Pages. .

0 0 43

- vừa được xem lúc

Deploy thủ công ứng dụng Django

Đối với một developer mà nói, mục đích cuối cùng của chúng ta khi phát triển một sản phẩm là có thể đưa sản phẩm ấy đến được với người dùng, và deploy là bước cuối cùng mà chúng ta cần thực hiện. Tron

0 0 259

- vừa được xem lúc

Docker – Những lý do bạn nên sử dụng Docker cho triển khai ứng dụng của bạn

Đối với những ma mới bắt đầu tập tẹ triển khai (deploy) ứng dụng thì một phần không nhỏ sẽ có chút bỡ ngỡ với Docker và những khái niệm liên quan. Phần lớn các nền tảng, framework, dịch vụ thứ 3 đều b

0 0 64