Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ’š [CI/CD] Actions 슀크립트 μˆ˜μ • #24

Merged
merged 9 commits into from
Jan 19, 2024
59 changes: 43 additions & 16 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,37 @@ jobs:
java-version: '17'
distribution: 'temurin'

- name: Make application.yml
- name: 2) Convert to prod config
run: |
cd ./src/main/resources
touch ./application.yml
echo "${{ secrets.APPLICATION_YML }}" > ./application.yml
[ -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_USERNAME }}
spring.datasource.password: ${{ secrets.DB_PW }}
spring.jwt.secret: ${{ secrets.JWT_SECRET }}
spring.jwt.token.access-expiration-time: ${{ secrets.JWT_ACCESS_EXPIRATION_TIME }}
spring.jwt.token.refresh-expiration-time: ${{ secrets.JWT_REFRESH_EXPIRATION_TIME }}
spring.data.redis.host: ${{ secrets.REDIS_HOST }}
spring.data.redis.port: ${{ secrets.REDIS_PORT }}

- name: 3) Set prod.yml - Debug
run: |
cat ./src/main/resources/application-prod.yml

- name: Grant execute permission for gradlew and build
run: |
chmod +x ./gradlew
./gradlew clean
./gradlew build -x test

cd:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -68,16 +94,17 @@ jobs:
username: ec2-user
key: ${{ secrets.PRIVATE_KEY }} # pem key
script: |
sudo docker stop sponus-docker
sudo docker rm sponus-docker
sudo docker rmi ${{ secrets.DOCKER_USERNAME }}/sponus-docker
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/sponus-docker

sudo docker stop my-redis
sudo docker rm my-redis
sudo docker rmi redis

sudo docker pull redis
sudo docker network create my-network
sudo docker run --name my-redis --network my-network -d redis
sudo docker run -it -d -p 8080:8080 --name sponus-docker -e TZ=Asia/Seoul --network my-network ${{ secrets.DOCKER_USERNAME }}/sponus-docker
sudo docker stop sponus-docker
sudo docker rm sponus-docker
sudo docker rmi ${{ secrets.DOCKER_USERNAME }}/sponus-docker
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/sponus-docker

sudo docker stop my-redis
sudo docker rm my-redis
sudo docker rmi redis

sudo docker pull redis
sudo docker network create my-network
sudo docker run --name my-redis --network my-network -d redis
sudo docker run -e SPRING_PROFILES_ACTIVE=prod -it -d -p 8080:8080 --name sponus-docker -e TZ=Asia/Seoul --network my-network ${{ secrets.DOCKER_USERNAME }}/sponus-docker

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Created by https://www.toptal.com/developers/gitignore/api/java,gradle
# Edit at https://www.toptal.com/developers/gitignore?templates=java,gradle

*-local.yml

# Mac os
*.Ds_Store

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:17-jdk
ARG JAR_FILE=./build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java", "-Dspring.profiles.active=docker", "-jar", "/app.jar"]
ENTRYPOINT ["java", "-Dspring.profiles.active=prod", "-jar", "/app.jar"]
29 changes: 29 additions & 0 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
server:
port: 8080

spring:
datasource:
driver-class-name: org.postgresql.Driver
url: ${DB_URL}
username: ${DB_USERNAME}
password: ${DB_PW}

jpa:
database: postgresql
hibernate:
ddl-auto: update
open-in-view: false
show-sql: true
generate-ddl: true

jwt:
secret: ${JWT_SECRET}
token:
access-expiration-time: ${JWT_ACCESS_EXPIRATION_TIME}
refresh-expiration-time: ${JWT_REFRESH_EXPIRATION_TIME}

data:
redis:
host: ${REDIS_HOST}
port: ${REDIS_PORT}

29 changes: 2 additions & 27 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,3 @@
server:
port: 8080

spring:
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/test
username: root
password: root

jpa:
database: postgresql
hibernate:
ddl-auto: update
open-in-view: false
show-sql: true
generate-ddl: true

jwt:
secret: "dkqorhvmekgkwlaksdltlrksdpanjfajrdmausdksehlrpTwlckawk"
token:
access-expiration-time: 43200
refresh-expiration-time: 604800

data:
redis:
host: localhost
port: 6379
profiles:
active: local
Loading