Merge pull request #58 from NimsHub/development #31
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: CD to On Premise server | |
on: | |
push: | |
branches: [ "on-premise-release" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
env: | |
CR_PAT: ${{ secrets.CR_PAT }} | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: dorny/paths-filter@v2 | |
id: changes | |
with: | |
base: ${{ github.ref }} | |
filters: | | |
src: | |
- 'src/**' | |
- 'Dockerfile' | |
conf: | |
- 'docker-compose.yml' | |
- 'nginx/**' | |
ml: | |
- 'src/main/resources/scripts/**' | |
- 'src/main/resources/models/**' | |
- 'src/main/resources/scalars/**' | |
- name: Set up JDK 17 | |
if: steps.changes.outputs.src == 'true' | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
cache: maven | |
- name: Build with Maven | |
if: steps.changes.outputs.src == 'true' | |
run: mvn -B clean package -DskipTests --file pom.xml | |
- name: Maven verify | |
if: steps.changes.outputs.src == 'true' | |
run: mvn -B clean verify | |
- name: Build image and Publish | |
if: steps.changes.outputs.src == 'true' | |
run: | | |
echo $CR_PAT | docker login ghcr.io --username ${{secrets.GHCR_USER}} --password-stdin | |
docker build --tag ghcr.io/${{secrets.GHCR_USER}}/bio-beacon-api:latest . | |
docker push ghcr.io/${{secrets.GHCR_USER}}/bio-beacon-api:latest | |
- name: Copy configuration files | |
if: steps.changes.outputs.conf == 'true' | |
uses: appleboy/scp-action@v0.1.4 | |
with: | |
host: ${{ secrets.SERVER_IP }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
port: ${{ secrets.SERVER_PORT }} | |
key: ${{ secrets.SERVER_KEY }} | |
source: "docker-compose.yml,nginx/**" | |
target: ${{ secrets.SERVER_TARGET_LOCATION }} | |
- name: Copy ML Files | |
if: steps.changes.outputs.ml == 'true' | |
uses: appleboy/scp-action@v0.1.4 | |
with: | |
host: ${{ secrets.SERVER_IP }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
port: ${{ secrets.SERVER_PORT }} | |
key: ${{ secrets.SERVER_KEY }} | |
source: "src/main/resources/scripts/**,src/main/resources/scalars/**,src/main/resources/models/**" | |
target: ${{ secrets.SERVER_TARGET_LOCATION }} | |
- name: Pull and Redeploy the Application | |
if: steps.changes.outputs.src == 'true' || steps.changes.outputs.conf == 'true' | |
uses: appleboy/ssh-action@v0.1.10 | |
with: | |
host: ${{ secrets.SERVER_IP }} | |
username: ${{ secrets.SERVER_USERNAME }} | |
port: ${{ secrets.SERVER_PORT }} | |
key: ${{ secrets.SERVER_KEY }} | |
script: | | |
cd ${{ secrets.SERVER_TARGET_LOCATION}} | |
docker pull ghcr.io/${{secrets.GHCR_USER}}/bio-beacon-api:latest | |
docker build -t ghcr.io/nimshub/nginx -f nginx/Dockerfile . | |
docker compose up -d --build | |
docker image prune -f |