This walkthrough is for auto-deploying a React application to a Digital Ocean droplet.
sudo apt install nginx git curl wget
.github/workflows/main.yml
file in your project directory.Paste the following text.
# This is a basic workflow to help you get started with Actions
name: Continuous Deploy
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: self-hosted
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
npm install
npm run build --if-present
# Last step, run it!
, do not run the command listed. Instead of executing ./run.sh
, you will execute sudo ./svc.sh install
.sudo ./svc.sh start
Now your droplet will be the runner for building your application.
cd ./_work/{project name}/{project name}
pwd
later.ls
and you'll see your project. It will also have a build
directory since your Action ran npm run build
.cd /etc/nginx/sites-available
sudo vim react-app
pwd
and copy the path.Put the following text into the react-app
file. Replace everthing inside {}
with the appropriate value.
server {
server_name {your DNS entry - e.g. app.domain.com};
root {paste what you copied in the previous step}/build;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html$is_args$args;
}
access_log /var/log/nginx/client.log;
}
sudo ln -s /etc/nginx/sites-available/react-app /etc/nginx/sites-enabled/react-app
sudo systemctl daemon-reload
sudo service nginx reload