[REFACTOR] 코드리뷰 #333
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: SB CI/CD with Gradle | |
on: | |
push: | |
branches: ["main", "dev"] | |
pull_request: | |
branches: ["main", "dev"] | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Set prod.yml | |
run: | | |
cd ./src/main/resources | |
sed -i 's|${DB_URL}|'"${{ secrets.DB_URL }}"'|g' application-prod.yml | |
sed -i 's|${DB_USER}|'"${{ secrets.DB_USER }}"'|g' application-prod.yml | |
sed -i 's|${DB_PW}|'"${{ secrets.DB_PW }}"'|g' application-prod.yml | |
sed -i 's|${S3_BUCKET}|'"${{ secrets.S3_BUCKET }}"'|g' application-prod.yml | |
sed -i 's|${S3_REGION}|'"${{ secrets.S3_REGION }}"'|g' application-prod.yml | |
sed -i 's|${S3_ACCESS_KEY}|'"${{ secrets.S3_ACCESS_KEY }}"'|g' application-prod.yml | |
sed -i 's|${S3_SECRET_KEY}|'"${{ secrets.S3_SECRET_KEY }}"'|g' application-prod.yml | |
sed -i 's|${KAKAO_CLIENT_ID}|'"${{ secrets.KAKAO_CLIENT_ID }}"'|g' application-prod.yml | |
sed -i 's|${KAKAO_CLIENT_SECRET}|'"${{ secrets.KAKAO_CLIENT_SECRET }}"'|g' application-prod.yml | |
- name: Grant permission | |
run: chmod +x ./gradlew | |
- name: Build with Gradle | |
run: ./gradlew bootJar | |
- name: Docker build and push | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build --platform linux/amd64 -t ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} . | |
docker push ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} | |
- name: Deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_NAME }} | |
key: ${{ secrets.EC2_KEY }} | |
port: 22 | |
script: | | |
sudo usermod -aG docker $USER | |
sudo docker stop showhoo-server || true | |
sudo docker rm showhoo-server || true | |
sudo docker image rm ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} || true | |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} | |
sudo docker run -e SPRING_PROFILES_ACTIVE=prod \ | |
-e DB_URL=${{ secrets.DB_URL }} \ | |
-e DB_USER=${{ secrets.DB_USER }} \ | |
-e DB_PASSWORD=${{ secrets.DB_PW }} \ | |
-e S3_BUCKET=${{ secrets.S3_BUCKET }} \ | |
-e S3_REGION=${{ secrets.S3_REGION }} \ | |
-e S3_ACCESS_KEY=${{ secrets.S3_ACCESS_KEY }} \ | |
-e S3_SECRET_KEY=${{ secrets.S3_SECRET_KEY }} \ | |
-e KAKAO_CLIENT_ID=${{ secrets.KAKAO_CLIENT_ID }} \ | |
-e KAKAO_CLIENT_SECRET=${{ secrets.KAKAO_CLIENT_SECRET }} \ | |
-e EC2_HOST=${{ secrets.EC2_HOST }} \ | |
--name showhoo-server -p 8081:8081 -d ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKER_REPO }} |