This walkthrough is for auto-deploying a React application to a Digital Ocean droplet.
- Create the new DNS entry in the Networking tab on Digital Ocean. Point it to the droplet you are configuring.
- SSH into your server in a new terminal.
sudo apt install nginx git curl wget
- Create
.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
- Commit and push that to Github.
- Go to the Settings tab of your Github repo.
- Go to Actions tab on left.
- Click on Runners in the new General nav item that appears.
- Click button to create new self-hosted runner.
- Click the Linux radio button.
- Follow the steps and accept all the defaults when asked.
- When you get to
# Last step, run it!
, do not run the command listed. Instead of executing./run.sh
, you will executesudo ./svc.sh install
. - Then execute
sudo ./svc.sh start
Now your droplet will be the runner for building your application.
- Go to your project directory and make some trivial change.
- Commit and push change to Github.
- You can watch the process by clicking on the Actions tab on Github and watch your app be built for production.
- Once the Action is complete, go back to the terminal where you are in your droplet.
cd ./_work/{project name}/{project name}
- Stay in this directory. You'll need to run
pwd
later. - Run
ls
and you'll see your project. It will also have abuild
directory since your Action rannpm run build
.
cd /etc/nginx/sites-available
sudo vim react-app
- Go back to the other terminal where you are in the directory that the Github Action created for you.
- Run
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; }
- Save and exit.
sudo ln -s /etc/nginx/sites-available/react-app /etc/nginx/sites-enabled/react-app
sudo systemctl daemon-reload
sudo service nginx reload