This repository has been archived by the owner on Sep 29, 2024. It is now read-only.
Add files via upload #266
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: Backend Build | Test | Deployment | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
name: Build Main Branch | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Source Code | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
cache: gradle | |
- name: Adding secret | |
run: | | |
echo "spring.datasource.password= ${{secrets.POSTGRES_PW}}" >> "backend2shine/src/main/resources/application.properties" | |
cat backend2shine/src/main/resources/application.properties | |
- name: Build Initial with Gradle | |
working-directory: ./backend2shine | |
run: ./gradlew build #otherwise ./gradlew bootBuildImage | |
- name: Build and Push Docker Image | |
uses: mr-smithers-excellent/docker-build-push@v6 | |
with: | |
image: techn1c/backend2shine | |
tags: latest | |
registry: docker.io | |
directory: backend2shine | |
dockerfile: backend2shine/Dockerfile | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
testing: | |
needs: build | |
name: Run Backend Tests | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Source Code | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
cache: gradle | |
- name: Adding secret | |
run: | | |
echo "spring.datasource.password= ${{secrets.POSTGRES_PW}}" >> "backend2shine/src/main/resources/application.properties" | |
cat backend2shine/src/main/resources/application.properties | |
- name: Execute Gradle Testing | |
working-directory: ./backend2shine | |
run: ./gradlew test | |
deploy_to_droplet: | |
runs-on: ubuntu-latest | |
needs: testing | |
name: Deploy to Digital Ocean Droplet | |
steps: | |
- name: Connect with SSH and Deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ${{ secrets.SSH_USER }} | |
key: ${{ secrets.SSH_KEY }} | |
script: | | |
docker login | |
docker stop backend2shine | |
docker remove backend2shine | |
docker pull techn1c/backend2shine:latest | |
docker run --name backend2shine -p 8081:8081 -d techn1c/backend2shine:latest | |