요야 보호사 프로필 업데이트 기능 수정 #181
This file contains hidden or 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: CI/CD with Gradle | |
| on: | |
| push: | |
| branches: [ "main", "dev" ] | |
| pull_request: | |
| branches: [ "main", "dev" ] | |
| env: | |
| S3_BUCKET_NAME: galaxy-dev-bucket | |
| permissions: | |
| contents: read | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'adopt' | |
| - name: Make application.yml | |
| run: | | |
| cd src/main/resources | |
| cat << 'EOF' > application.yml | |
| ${{ secrets.YML }} | |
| EOF | |
| shell: bash | |
| - name: Make application-db.yml | |
| run: | | |
| cd ./src/main/resources | |
| touch ./application-db.yml | |
| echo "${{ secrets.YML_DB }}" > ./application-db.yml | |
| shell: bash | |
| - name: Make application-jwt.yml | |
| run: | | |
| cd ./src/main/resources | |
| touch ./application-jwt.yml | |
| echo "${{ secrets.YML_JWT }}" > ./application-jwt.yml | |
| shell: bash | |
| - name: Make application-mail.yml | |
| run: | | |
| cd ./src/main/resources | |
| touch ./application-mail.yml | |
| echo "${{ secrets.YML_MAIL }}" | sed 's/\\n/\n/g' > ./application-mail.yml | |
| shell: bash | |
| - name: Make application-oauth.yml | |
| run: | | |
| cd ./src/main/resources | |
| touch ./application-oauth.yml | |
| echo "${{ secrets.YML_OAUTH }}" | sed 's/\\n/\n/g' > ./application-oauth.yml | |
| shell: bash | |
| - name: Make application-aws.yml | |
| run: | | |
| cd ./src/main/resources | |
| echo "${{ secrets.YML_AWS }}" | sed 's/\\n/\n/g' > application-aws.yml | |
| shell: bash | |
| # Gradle을 캐싱 -> 빌드 속도가 증가하는 효과 | |
| - name: Gradle 캐싱 | |
| 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: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v1 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ap-northeast-2 | |
| - name: Build with Gradle | |
| run: | | |
| chmod +x ./gradlew | |
| ./gradlew clean build --exclude-task test | |
| - name: Check generated JAR file | |
| run: ls -l build/libs/ | |
| - name: Docker build & push to docker repo | |
| run: | | |
| echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin | |
| docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/blaybus-backend . | |
| docker push ${{ secrets.DOCKERHUB_USERNAME }}/blaybus-backend:latest | |
| - name: Sync Bucket | |
| env: | |
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| AWS_EC2_METADATA_DISABLED: true | |
| run: | | |
| aws s3 sync \ | |
| --region ap-northeast-2 \ | |
| ./build s3://$S3_BUCKET_NAME/ \ | |
| --delete | |
| working-directory: ./ | |
| - name: Deploy to server | |
| uses: appleboy/ssh-action@master | |
| id: deploy | |
| with: | |
| host: ${{ secrets.HOST }} | |
| username: ubuntu | |
| key: ${{ secrets.KEY }} | |
| envs: GITHUB_SHA | |
| script: | | |
| cd /home/ubuntu/galaxyDev | |
| echo "🛑 Stopping and removing existing backend-container" | |
| docker-compose down backend-container | |
| echo "🚀 Updating to the backend-container:latest image" | |
| docker-compose pull backend-container | |
| echo "✅ Starting the new container" | |
| docker-compose up -d backend-container |