Merge pull request #64 from kohei-s/auto-translation #29
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 | |
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@v2 | |
- uses: actions/download-artifact@v2 | |
with: | |
name: frontend-build | |
path: backend/src/main/resources/static | |
- name: Set up JDK | |
uses: actions/setup-java@v2 | |
with: | |
java-version: '20' | |
distribution: 'adopt' | |
cache: 'maven' | |
- name: Build with maven | |
run: mvn -B package --file backend/pom.xml | |
- uses: actions/upload-artifact@v2 | |
with: | |
name: app.jar | |
path: backend/target/kotokoapp.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: kokoyuyu | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Build and push | |
uses: docker/build-push-action@v2 | |
with: | |
push: true | |
tags: kokoyuyu/kotoko-app:latest | |
context: . | |
deploy: | |
runs-on: ubuntu-latest | |
needs: push-to-docker-hub | |
steps: | |
- name: Restart docker container | |
uses: appleboy/ssh-action@master | |
with: | |
host: ec2-3-79-82-35.eu-central-1.compute.amazonaws.com | |
username: ec2-user | |
key: ${{ secrets.SSH_KEY }} | |
script: | | |
docker stop ec2-user | |
docker rm ec2-user | |
docker run --pull=always --name ec2-user --publish 80:8080 --detach --env MONGO_DB_URI=${{ secrets.MONGO_DB_URI }} --env DEEPL_API_KEY=${{ secrets.DEEPL_API_KEY }} kokoyuyu/kotoko-app:latest | |
sleep 15s | |
docker logs ec2-user | |
- name: Check the deployed service URL | |
uses: jtalk/url-health-check-action@v3 | |
with: | |
# url: http://ec2-3-79-82-35.eu-central-1.compute.amazonaws.com | |
url: https://kotoko.de | |
max-attempts: 3 | |
retry-delay: 5s | |
retry-all: true |