Skip to content

Merge pull request #147 from EveryUniv/dev #44

Merge pull request #147 from EveryUniv/dev

Merge pull request #147 from EveryUniv/dev #44

Workflow file for this run

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
name: Dev_CD
on:
push:
branches: [ "dev_deploy" ]
permissions:
contents: read
jobs:
check_repo:
runs-on: ubuntu-latest
outputs:
cd-skip: ${{ steps.check_repo.outputs.cd-skip-value }}
steps:
- uses: actions/checkout@v3
- name: Check Repo
run: |
if [ "$GITHUB_REPOSITORY" != "YOUR_USER/YOUR_REPO_NAME" ]; then
echo 'cd-skip-value=true' >> $GITHUB_OUTPUT
else
echo 'cd-skip-value=false' >> $GITHUB_OUTPUT
fi
skip_cd:
needs: check_repo
if: github.repository != 'EveryUniv/next-student-council-backend'
runs-on: ubuntu-latest
steps:
- name: Skip CD
run: |
echo "CD will be terminated soon..."
exit 0
build:
runs-on: ubuntu-latest
if: github.repository == 'EveryUniv/next-student-council-backend'
needs: check_repo
environment: dev
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'
- name: Make test properties
env:
PROPERTIES: ${{ secrets.PROPERTIES_TEST }}
run: |
mkdir -p ./src/test/resources && cd "$_"
touch ./application.yml
echo $PROPERTIES | base64 --decode > application.yml
shell: bash
- name: Gradle Init
run: gradle init
- name: Build with Gradle
uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0
with:
arguments: build
gradle-version: '7.6'
- name: Docker build
env:
USERNAME: ${{ secrets.DOCKER_USERNAME }}
REPO: ${{ secrets.DOCKER_REPO }}
run: |
docker build -t $USERNAME/$REPO:${GITHUB_SHA::7} -t $USERNAME/$REPO:latest .
- name: Docker push
env:
USERNAME: ${{ secrets.DOCKER_USERNAME }}
PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
REPO: ${{ secrets.DOCKER_REPO }}
run: |
docker login -u $USERNAME -p $PASSWORD
docker push $USERNAME/$REPO:${GITHUB_SHA::7}
docker push $USERNAME/$REPO:latest
- name: SSH Remote Commands
uses: appleboy/ssh-action@master
env:
REPO: ${{ secrets.DOCKER_REPO }}
with:
host: ${{ secrets.SERVER_HOST }}
username: ubuntu
key: ${{ secrets.NEXT_PRIVATE_PEM_KEY }}
proxy_host: ${{ secrets.BASTION_IP }}
proxy_username: ubuntu
proxy_key: ${{ secrets.NEXT_PRIVATE_PEM_KEY }}
envs: GITHUB_SHA,REPO
script: |
./deploy.sh ${{ secrets.DOCKER_USERNAME }} $REPO ${GITHUB_SHA::7}