My source code repo is hosted on GitHub and I'm wondering how to implement a CI/CD github actions pipeline for testing, build and deploy of my MERN application to DigitalOcean. I have admin_frontend, user_frontend, backend folders in the root.
What I want to achieve if I push to master branch, run CI/CD workflows so:
- Build apps (production react build for 2 frontend)
- run tests (I have only some Jest test cases in 1 frontend app)
- deploy to my digital ocean droplet
I don't know how to solve this since I have NOT just 1 frontend app in my github repository but 2 frontend and 1 backend app. If you have any workflow template for that structure, idea how to do this I appreciate it.
Do I need to create just one .github/workflows/main.yml in the root or 3 into all apps?
Currenctly I can deploy to my Digital Ocean droplet the 3 apps by running this script:
#build admin frontend
docker build -t admin-fe ./admin_frontend_app
docker save -o ./admin-fe.tar admin-fe
#build backend and frontend
docker build -t main-be ./backend & docker build -t main-fe ./frontend
docker save -o ./main-be.tar main-be & docker save -o ./main-fe.tar main-fe
#deploy services
ssh root@IPADDRESS "pwd && mkdir -p ~/apps/mern && cd ~/apps/mern && ls -al && echo 'im in' && rm admin-fe.tar && rm main-be.tar && rm main-fe.tar &> /dev/null"
#upload admin-fe.tar to VM via ssh
scp ./admin-fe.tar root@IPADDRESS:~/apps/mern/
#upload main-be.tar and main-fe.tar to VM via ssh
scp ./main-be.tar ./main-fe.tar root@IPADDRESS:~/apps/mern/
ssh root@IPADDRESS "cd ~/apps/mern && ls -1 *.tar | xargs --no-run-if-empty -L 1 docker load -i"
#sudo docker compose up
ssh root@IPADDRESS "cd ~/apps/mern && sudo docker-compose up"
CodePudding user response:
Considering you have one single repository it can be convenient creating a single workflow which runs all steps:
- build and test user frontend
- build admin frontend
- build backend
- deploy apps (you could look at
digitalocean/action-doctl@v2
to accomplish this)
The workflow is convenient when you want to deploy them all at once (also I think you wouldn't do this upon each git push
otherwise every change would redeploy them all).
The option you mention (3 workflows) is also a valid solution when you want to keep the components independent: for example build/push the admin frontend without affecting the others.
CodePudding user response:
Where to put build images, and actually I have 4 containers like nginx, admin-fe, main-fe and main-be which should run. I also use docker-compose.
name: CICD
on:
push:
branches:
- master
jobs:
main-fe_build:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
working-directory: frontend
steps:
- name: Checkout