backend deploy dev #123
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
# Develop 브랜치에 BE코드 머지 시 | |
# 깃헙 러너에서 빌드 후 jar 업로드 | |
# 셀프 호스트 러너에서 jar 다운로드 후 was로 배포 | |
name: backend deploy dev | |
on: | |
workflow_dispatch: | |
pull_request: | |
types: | |
- closed | |
branches: ["develop"] | |
paths: | |
- "backend/**" | |
permissions: | |
contents: read | |
jobs: | |
build-and-upload: | |
# if: github.event.pull_request.merged == true | |
runs-on: ubuntu-22.04 | |
defaults: | |
run: | |
working-directory: backend | |
steps: | |
- name: Set up Repository | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: "17" | |
distribution: "corretto" | |
- name: Give permission for Gradle | |
run: chmod +x gradlew | |
- name: Cache Gradle | |
id: cache-gradle | |
uses: actions/cache@v4 | |
with: | |
path: ~/.gradle/caches | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Build with Gradle | |
run: ./gradlew bootJar | |
- name: Upload jar file artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: BackendApplicationJar | |
path: backend/build/libs/*.jar | |
deploy: | |
needs: build-and-upload | |
runs-on: self-hosted | |
env: | |
DEV_DEPLOY_SCRIPT: ${{ secrets.DEV_BACK_DEPLOY_SCRIPT }} | |
steps: | |
- name: Remove previous version jar | |
working-directory: backend/dev/ | |
run: rm -f team-by-team-*.jar | |
- name: Make backup | |
run: | | |
rm -rf /home/ubuntu/team-by-team/backend/backup/* | |
mv /home/ubuntu/team-by-team/backend/current/* /home/ubuntu/team-by-team/backend/backup/ | |
- name: Download jar file from artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: BackendApplicationJar | |
path: backend/dev/ | |
- name: Checkout for get property | |
uses: actions/checkout@v4 | |
with: | |
submodules: true | |
token: ${{ secrets.TBT_REPO_TOKEN }} | |
path: backend/dev/ | |
sparse-checkout: | | |
backend/src/main/resources/security/application-dev.yml | |
sparse-checkout-cone-mode: false | |
- name: Move dev application.yml | |
working-directory: backend/dev/ | |
run: | | |
cp 2023-team-by-team/backend/src/main/resources/security/application-dev.yml ./ | |
- name: Move jar file and application yml to deploy directory | |
working-directory: backend/dev/ | |
run: | | |
mv team-by-team-*.jar /home/ubuntu/team-by-team/backend/current/team-by-team.jar | |
mv application-dev.yml /home/ubuntu/team-by-team/backend/current/ | |
- name: Deploy to WAS | |
working-directory: backend/dev/ | |
run: | | |
echo "$DEV_DEPLOY_SCRIPT" > dev-deploy.sh | |
chmod 700 dev-deploy.sh | |
sudo ./dev-deploy.sh |