Java Springboot Deployment using GitHub - deployment

I am trying to deploy my Springboot App to my Linux VM using GitHub. The deployment itself works, but the GitHub Action does not stop running since the last command executed is still running but should not be stopped. How can I solve this?
name: Backend Deployment to Linux VM
on:
push:
branches:
- main
jobs:
build-and-deploy:
name: Backend Deployment to Linux VM
runs-on: ubuntu-latest
steps:
- name: update and start project
uses: appleboy/ssh-action#master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: |
kill -9 $(lsof -t -i:8080)
cd /home/github_deploy_backend
cd backend-P2cinema
git pull
mvn clean package
nohup java -jar target/*.jar &

Related

Github actions PM2 start command not starting process

I'm facing issue with PM2 start. when i push code to master branch all below steps working correctly without any issue. but when i login to my EC2 using SSH and check for pm2 list there is no process showing.
I've google a lot but didn't get any working solution.
Below is my workflows yml file
name: Node.js CI
on:
push:
branches: [ "master" ]
jobs:
build:
runs-on: self-hosted
strategy:
matrix:
node-version: [14.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout#v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: pwd
- run: npm ci
- run: npm run build --if-present
- run: pm2 kill
- run: echo 'pm2 process killed successfully'
- run: pm2 start dist/main.js
- run: pm2 list

Github CI/CD reuse step

I'm kinda beginner with CI/CD, but I wrote a code that deploys Vue/Vite project to Ubuntu VPS. But, it's not as it should be. So what am I doing actually?
First as usual, installing the project and building it.
jobs:
build:
name: "Build"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Install
run: yarn
- name: Build
run: yarn build
So the problem is when that passes. I'm connecting to ssh like:
deploy:
name: "Deploy"
needs: project_setup
runs-on: ubuntu-latest
steps:
- name: Deploy to server
uses: appleboy/ssh-action#master
env:
GIT_REPO: Comet-Frontend
GIT_SSH: ${{ github.repositoryUrl }}
with:
host: ${{ secrets.VPS_IP }}
username: ${{ secrets.VPS_USER }}
password: ${{ secrets.VPS_PASSWORD }}
port: ${{ secrets.VPS_PORT }}
envs: GIT_SSH, GIT_REPO
and at the very bottom:
script: |
cd /var/www/vue
git pull
ls
yarn
yarn build
cp -R /root/Frontend/dist /var/www/vue
So I would like to define ssh connection once and run those scripts separately with different step names. Is that possible or I have to connect to ssh for every step?
If each step needs SSH to access either a remote repository URL or your VPS target server, then yes, you would need SSH to each step.
The alternative being to copy a deployment script to the server (through SSH): the steps included in that script could be executed directly on that server (where the script has been copied). No need for SSH then for that script execution, since it is already at target.

Running a Docker Image via SSH Github Actions

so I'm currently trying to make GitHub Actions/CI SSH into my VPS and run a docker image. Although the main problem is that the job doesn't finish up after running the final command.
This is my YML file:
name: SSH & Deploy Image
on:
workflow_run:
workflows: ["Timmy Docker Build"]
branches: [ main ]
types:
- completed
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Run Docker CMD
uses: appleboy/ssh-action#master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.PORT }}
script: |
docker stop ss-timmy && docker rm ss-timmy
docker pull spaceturtle0/ss-timmy:latest
docker run --env-file=Timmy-SchoolSimplified/.env spaceturtle0/ss-timmy &
Regardless of having put the & sign at the final script command, the process just hangs until the process is killed. Is there something to fix this?
You should use -d flag that means detached instead & sign for last docker command. So full command will be:
docker run -d --env-file=Timmy-SchoolSimplified/.env spaceturtle0/ss-timmy

How to create a dotenv file using Github Actions in the Deploy steps?

I'm learning CI CD to deploy REST API to VPS using Github Actions.
I am confused about how to make a dotenv file so that it is on the VPS server using Github Actions, because this REST API requires a Jsonwebtoken key and I have to insert it in the .env file. I've tried several ways but nothing works.
If you have the answer, please modify my .yml file below and include your answer so I can understand it clearly.
I really appreciate any answer.
name: Node.js CICD
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
- name: create env file
run: |
touch .env
echo JWT_ACCESS_TOKEN_SECRET=${{ secrets.JWT_ACCESS_TOKEN_SECRET }} >> .env
- name: install and test
run: |
npm i
npm run build --if-present
npm run test
env:
CI: true
deploy:
needs: [test]
runs-on: ubuntu-latest
steps:
- name: deploy with SSH
uses: appleboy/ssh-action#master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.PRIVATE_KEY }}
port: 22
script: |
cd ~/apps/routeros-api
git pull origin master
npm i --production
pm2 restart routeros-api

gh-pages deployment issue, job fails on deploy. The directory you're trying to deploy ... doesn't exist

gh-pages deployment fails with next error: My repository failed job
Checking configuration and starting deployment… 🚦
Error: The directory you're trying to deploy named /home/runner/work/azure-flask-react/azure-flask-react/dist doesn't exist. Please double check the path and any prerequisite build scripts and try again. ❗
Deployment failed! ❌
I'm trying to deploy ReactApp at Github and besides deploy Python-Flask backend hosted at Azure and back-app has its automatically generated job yml.
But for front-app I followed this answer and manually added second job in yml because I need to provide env.variables.
My backend deployment succeeds but front-app constantly fails because of duplicated path
/home/runner/work/azure-flask-react/azure-flask-react/dist
Here is my yml and package.json but there is no any extra mentioning of that directory...
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions
name: Build and deploy Python app to Azure Web App - first-py-app
on:
push:
branches:
- main
workflow_dispatch:
jobs:
front-build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v1
- name: Build
run: |
npm --prefix front-app install
npm --prefix front-app run-script build
env:
REACT_DEV_SERVER_URL: ${{ secrets.REACT_DEV_SERVER_URL }},
REACT_DEV_FRONT_APP_URL: ${{ secrets.REACT_DEV_FRONT_APP_URL }}
- name: Deploy
uses: JamesIves/github-pages-deploy-action#releases/v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN_KEY }}
BRANCH: gh-pages
FOLDER: dist
back-build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#master
- name: Set up Python version
uses: actions/setup-python#v1
with:
python-version: '3.8'
- name: Build using AppService-Build
uses: azure/appservice-build#v2
with:
platform: python
platform-version: '3.8'
- name: 'Deploy to Azure Web App'
uses: azure/webapps-deploy#v2
with:
app-name: 'first-py-app'
slot-name: 'production'
publish-profile: ${{ secrets.AzureAppService_PublishProfile_7edcdecca83a4354a87943f94bb32fca }}
{
...
"homepage": "https://nikonov91-dev.github.io/azure-flask-react",
"scripts": {
...
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
},
}
and my file structure
azure-proj
|-front-app (containing reactjs)
|-package.json
|-node_modules
|-src
|-app.py (python-flask application which deploys successfully)
I misunderstood the issue message, the problem was not duplicating the problem was the missed inner path passed in FOLDER in gh-pages YML settings
There was a hint in BUILD step
And one more thing: do not forget to get and add to GH your personal-access-token