Deploying my java app to VPS with Github actions and Dockerization

This is the deployment code I got from our existing project
name: build and deploy movie app service backend

on:
push:
branches:
- dev

jobs:
build-deploy:
name: build and deploy city-app-movie-backend
runs-on: ubuntu-22.04

steps:
- name: checkout code
uses: actions/checkout@v3

- name: setup jdk 21
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: 21

- name: grant execute permission for gradlew
run: chmod +x ./gradlew

- name: build the app
run: ./gradlew clean build -x test

- name: login to docker hub
uses: docker/login-action@v1
with:
username: ragjn_the_goat
password: password

- name: push the docker image to docker hub
uses: docker/build-push-action@v4
with:
context: .
dockerfile: Dockerfile
push: true
tags: rag_jn_ep/city-app-movie-backend:latest

- name: Deploy on contabo
env:
SSH_PASS: rag_the_goat
run: |
sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no [email protected] << EOF
#Stop the existing container
docker stop city-app-movie-backend || true
docker rm city-app-movie-backend || true
docker pull rag_jn_ep/city-app-movie-backend:latest
docker run --name city-app-movie-backend -d -p 8086:8086 -p 9002:9002 --network my-bridge-network \
--mount type=bind,source=/var/log/movie-service,target=/logs \
rag_jn_ep/city-app-movie-backend:latest
EOF
name: build and deploy movie app service backend

on:
push:
branches:
- dev

jobs:
build-deploy:
name: build and deploy city-app-movie-backend
runs-on: ubuntu-22.04

steps:
- name: checkout code
uses: actions/checkout@v3

- name: setup jdk 21
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: 21

- name: grant execute permission for gradlew
run: chmod +x ./gradlew

- name: build the app
run: ./gradlew clean build -x test

- name: login to docker hub
uses: docker/login-action@v1
with:
username: ragjn_the_goat
password: password

- name: push the docker image to docker hub
uses: docker/build-push-action@v4
with:
context: .
dockerfile: Dockerfile
push: true
tags: rag_jn_ep/city-app-movie-backend:latest

- name: Deploy on contabo
env:
SSH_PASS: rag_the_goat
run: |
sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no [email protected] << EOF
#Stop the existing container
docker stop city-app-movie-backend || true
docker rm city-app-movie-backend || true
docker pull rag_jn_ep/city-app-movie-backend:latest
docker run --name city-app-movie-backend -d -p 8086:8086 -p 9002:9002 --network my-bridge-network \
--mount type=bind,source=/var/log/movie-service,target=/logs \
rag_jn_ep/city-app-movie-backend:latest
EOF
3 Replies
JavaBot
JavaBot2w ago
This post has been reserved for your question.
Hey @Rag...JN 🌌 🦡 👽 💰 🐊! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Rag...JN 🌌 🦡 👽 💰 🐊
So I assume I don't have to create any containers in the server, I just have to push this to github, and it will create the container? I don't know where to start from?
JavaBot
JavaBot2w ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
Want results from more Discord servers?
Add your server