Merge pull request #49 from toshydev/bugfix #44
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 SNEK" | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build-frontend: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/setup-node@v2 | |
with: | |
node-version: '18' | |
- name: Build Frontend | |
run: | | |
cd frontend | |
npm install | |
npm run build | |
- uses: actions/upload-artifact@v2 | |
with: | |
name: frontend-build | |
path: frontend/dist/ | |
build-backend: | |
runs-on: ubuntu-latest | |
needs: build-frontend | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up JDK | |
uses: actions/setup-java@v2 | |
with: | |
java-version: '20' | |
distribution: 'adopt' | |
cache: 'maven' | |
- uses: actions/download-artifact@v2 | |
with: | |
name: frontend-build | |
path: backend/src/main/resources/static | |
- name: Build with maven | |
run: mvn -B package --file backend/pom.xml | |
- uses: actions/upload-artifact@v2 | |
with: | |
name: app.jar | |
path: backend/target/netrunner.jar | |
push-to-docker-hub: | |
runs-on: ubuntu-latest | |
needs: build-backend | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: actions/download-artifact@v2 | |
with: | |
name: app.jar | |
path: backend/target | |
- name: Login to DockerHub | |
uses: docker/login-action@v1 | |
with: | |
username: toshymoshy | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build and push | |
uses: docker/build-push-action@v2 | |
with: | |
push: true | |
platforms: linux/arm64 | |
tags: toshymoshy/netrunner:aarch64 | |
context: . | |
deploy: | |
runs-on: ubuntu-latest | |
needs: push-to-docker-hub | |
steps: | |
- name: Restart docker container | |
uses: appleboy/ssh-action@master | |
with: | |
host: snekhome.click | |
port: ${{ secrets.SSH_PORT_SNEK }} | |
username: ${{ secrets.SSH_USERNAME_SNEK }} | |
password: ${{ secrets.SSH_PASSWORD_SNEK }} | |
script: | | |
docker stop netrunner | |
docker rm netrunner | |
docker run --pull=always --name netrunner -p 8080:8080 --restart always --detach --env MONGO_DB_URI="${{ secrets.MONGO_DB_URI }}" --env MAPBOX_ACCESS_TOKEN="${{ secrets.MAPBOX_ACCESS_TOKEN }}" --env GOOGLE_API_KEY="${{ secrets.GOOGLE_API_KEY }}" toshymoshy/netrunner:aarch64 | |
sleep 15s | |
docker logs netrunner | |
- name: Check the deployed service URL | |
uses: jtalk/url-health-check-action@v3 | |
with: | |
url: http://snekhome.click | |
max-attempts: 3 | |
retry-delay: 5s | |
retry-all: true |