claer #29
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" ] | |
pull_request: | |
branches: [ "main" ] | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: 1) Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: 2) Convert to prod config | |
run: | | |
cd ./src/main/resources | |
[ -e "application.yml" ] && rm application.yml | |
echo "spring:" > application.yml | |
echo " profiles:" >> application.yml | |
echo " active: prod" >> application.yml | |
- name: 3) Set prod.yml | |
uses: microsoft/variable-substitution@v1 | |
with: | |
files: ./src/main/resources/application-prod.yml | |
env: | |
spring.datasource.url: ${{ secrets.DB_URL }} | |
spring.datasource.username: ${{ secrets.DB_USER }} | |
spring.datasource.password: ${{ secrets.DB_PW }} | |
cloud.aws.s3.bucket: ${{ secrets.S3_BUCKET }} | |
cloud.aws.s3.region.static: ${{ secrets.S3_REGION }} | |
cloud.aws.s3.credentials.accessKey: ${{ secrets.S3_ACCESS_KEY }} | |
cloud.aws.s3.credentials.secretKey: ${{ secrets.S3_PRIVATE_KEY }} | |
oauth.kakao.client-id: ${{ secrets.OAUTH_KAKAO_CLIENT_ID }} | |
jwt.secret-key: ${{ secrets.JWT_SECRET }} | |
- name: 4) Grant permission | |
run: chmod +x ./gradlew | |
- name: 5) Build with Gradle | |
run: ./gradlew bootJar | |
- name: 6) Build docker and push | |
run: | | |
docker login -u ${{secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD}} | |
docker build --platform linux/amd64 -t ${{ secrets.DOCKER_REPO }} . | |
docker push ${{ secrets.DOCKER_REPO }} | |
# docker installation sudo apt-get update, sudo DEBIAN_FRONTEND=noninteractive apt-get install -y docker.io | |
- name: 7) SSH conn and run docker(deployment) | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_KEY }} | |
port: 22 | |
script: | | |
sudo docker stop timelapse-server | |
sudo docker rm timelapse-server | |
sudo docker image rm ${{ secrets.DOCKER_REPO }} | |
sudo docker pull ${{ secrets.DOCKER_REPO }} | |
docker run -e SPRING_PROFILES_ACTIVE=prod --name timelapse-server -p 8080:8080 -d ${{ secrets.DOCKER_REPO }} | |
# 권한문제로 도커실행 안될때 sudo usermod -aG docker $USER |