Merge pull request #25 from MarvinBo44/feinschliff #16
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: "Deploy App" | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build-frontend: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
- name: Build Frontend | |
working-directory: frontend | |
run: | | |
npm install --legacy-peer-deps | |
npm run build | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: frontend-build | |
path: frontend/dist/ | |
build-backend: | |
runs-on: ubuntu-latest | |
needs: build-frontend | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/download-artifact@v3 | |
with: | |
name: frontend-build | |
path: backend/src/main/resources/static | |
- name: Set up JDK | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'adopt' | |
cache: 'maven' | |
- name: Build with maven | |
run: mvn -B package --file backend/pom.xml | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: app.jar | |
#Change app.jar to your applications finalname.jar | |
path: backend/target/app.jar | |
push-to-docker-hub: | |
runs-on: ubuntu-latest | |
needs: build-backend | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/download-artifact@v3 | |
with: | |
name: app.jar | |
path: backend/target | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
#Set dockerhub username | |
username: marvmarv44 | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Build and push | |
uses: docker/build-push-action@v2 | |
with: | |
push: true | |
#Set dockerhub project (replace "accesscoder/testdeploy") | |
tags: marvmarv44/to_be_able:latest | |
context: . | |
deploy: | |
runs-on: ubuntu-latest | |
needs: push-to-docker-hub | |
steps: | |
- name: Restart docker container | |
uses: appleboy/ssh-action@master | |
with: | |
host: capstone-project.de | |
#Set App Name (replace "example" with your ssh user name) | |
username: bo-java-23-2-weather | |
password: ${{ secrets.SSH_PASSWORD }} | |
#Set App Name (replace "bo-java-23-2-pokemon" with your ssh user name) | |
#Set dockerhub project (replace "accesscoder/testdeploy") | |
#Set IP (replace "10.0.7.11" with your ip address) | |
script: | | |
sudo docker stop bo-java-23-2-weather | |
sudo docker rm bo-java-23-2-weather | |
sudo docker run --pull=always --name bo-java-23-2-weather --network capstones --ip 10.0.7.12 --detach --env MONGO_DB_URI=${{ secrets.MONGO_DB_URI }} marvmarv44/to_be_able:latest | |
sleep 15s | |
sudo docker logs bo-java-23-2-weather | |
- name: Check the deployed service URL | |
uses: jtalk/url-health-check-action@v3 | |
with: | |
#Set App Name (replace "bo-java-23-2-pokemon" with your ssh user name) | |
url: http://bo-java-23-2-weather.capstone-project.de | |
max-attempts: 3 | |
retry-delay: 5s | |
retry-all: true |