Merge pull request #170 from 4bujak-4bujak/feature/member_modal #138
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
# 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: Spring Boot & Gradle & EC2 & S3 & CodeDeploy CD | |
on: | |
push: | |
branches: [ "develop" ] | |
env: | |
PROJECT_NAME: sabujak | |
BUCKET_NAME: offispace-cd-bucket | |
CODE_DEPLOY_APP_NAME: offispace-application | |
DEPLOYMENT_GROUP_NAME: offispace-deploy-group | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Gradle Caching | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: make application.properties | |
run: | | |
touch ./src/main/resources/application.properties | |
echo "${{ secrets.APPLICATION_PROPERTIES }}" > ./src/main/resources/application.properties | |
- name: make application-dev.properties | |
run: | | |
touch ./src/main/resources/application-dev.properties | |
echo "${{ secrets.APPLICATION_PROPERTIES }}" > ./src/main/resources/application-dev.properties | |
- name: make logback-spring.xml | |
run: | | |
touch ./src/main/resources/logback-spring.xml | |
echo "${{ secrets.LOGBACK }}" | base64 --decode > ./src/main/resources/logback-spring.xml | |
- name: Create Firebase private key | |
id: create-firebase-private-key | |
uses: jsdaniell/create-json@1.1.2 | |
with: | |
name: "private-key.json" | |
json: ${{ secrets.FCM_PRIVATE_KEY }} | |
- name: Move Firebase private key to src/main/resources directory | |
run: | | |
mkdir -p ./src/main/resources/firebase | |
mv private-key.json ./src/main/resources/firebase/private-key.json | |
- name: Run chmod to make gradlew executable | |
run: chmod +x ./gradlew | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 | |
- name: Setup SSH Key | |
run: | | |
mkdir -p ~/.ssh | |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts | |
- name: Setup SSH Tunnel | |
run: | | |
ssh -f -o ExitOnForwardFailure=yes -L 3306:${{ secrets.RDS_HOST }}:3306 ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} -i ~/.ssh/id_rsa -N | |
- name: Build with Gradle Wrapper | |
run: ./gradlew clean build | |
- name: Make Zip File | |
run: zip -qq -r ./$GITHUB_SHA.zip . | |
shell: bash | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }} | |
aws-region: ap-northeast-2 | |
- name: Upload to S3 | |
run: aws s3 cp ./$GITHUB_SHA.zip s3://$BUCKET_NAME/$PROJECT_NAME/$GITHUB_SHA.zip | |
- name: Code Deploy To EC2 instance | |
run: | | |
aws deploy create-deployment \ | |
--application-name $CODE_DEPLOY_APP_NAME \ | |
--deployment-config-name CodeDeployDefault.AllAtOnce \ | |
--deployment-group-name $DEPLOYMENT_GROUP_NAME \ | |
--s3-location bucket=$BUCKET_NAME,bundleType=zip,key=$PROJECT_NAME/$GITHUB_SHA.zip | |
dependency-submission: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies. | |
# See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md | |
- name: Generate and submit dependency graph | |
uses: gradle/actions/dependency-submission@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 |