[docs] readme μμ± #188
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: Java CI with Gradle | |
on: | |
push: | |
branches: [ "dev" ] | |
pull_request: | |
branches: [ "dev" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# νκ²½λ³ yml νμΌ μμ±(1) - application.yml | |
- name: make application.yml | |
if: | | |
contains(github.ref, 'dev') || | |
(github.event_name == 'pull_request') | |
run: | | |
mkdir ./src/main/resources # resources ν΄λ μμ± | |
cd ./src/main/resources # resources ν΄λλ‘ μ΄λ | |
touch ./application.yml # application.yml μμ± | |
echo "${{ secrets.YML }}" > ./application.yml # github actionsμμ μ€μ ν κ°μ application.yml νμΌμ μ°κΈ° | |
shell: bash | |
# νκ²½λ³ yml νμΌ μμ±(2) - dev | |
- name: make application-dev.yml | |
if: | | |
contains(github.ref, 'dev') || | |
(github.event_name == 'pull_request') | |
run: | | |
cd ./src/main/resources | |
touch ./application-dev.yml | |
echo "${{ secrets.YML_DEV }}" > ./application-dev.yml | |
shell: bash | |
# νκ²½λ³ yml νμΌ μμ±(3) - oauth | |
- name: make application-oauth.yml | |
if: | | |
contains(github.ref, 'dev') || | |
(github.event_name == 'pull_request') | |
run: | | |
cd ./src/main/resources | |
touch ./application-oauth.yml | |
echo "${{ secrets.YML_OAUTH }}" > ./application-oauth.yml | |
shell: bash | |
# νκ²½λ³ yml νμΌ μμ±(4) - jwt | |
- name: make application-jwt.yml | |
if: | | |
contains(github.ref, 'dev') || | |
(github.event_name == 'pull_request') | |
run: | | |
cd ./src/main/resources | |
touch ./application-jwt.yml | |
echo "${{ secrets.YML_JWT }}" > ./application-jwt.yml | |
shell: bash | |
# νκ²½λ³ yml νμΌ μμ±(5) - S3 | |
- name: make application-s3.yml | |
if: | | |
contains(github.ref, 'dev') || | |
(github.event_name == 'pull_request') | |
run: | | |
cd ./src/main/resources | |
touch ./application-s3.yml | |
echo "${{ secrets.YML_S3 }}" > ./application-s3.yml | |
shell: bash | |
# νκ²½λ³ yml νμΌ μμ±(6) - rabbitMQ | |
- name: make application-mq.yml | |
if: | | |
contains(github.ref, 'dev') || | |
(github.event_name == 'pull_request') | |
run: | | |
cd ./src/main/resources | |
touch ./application-mq.yml | |
echo "${{ secrets.YML_MQ }}" > ./application-mq.yml | |
shell: bash | |
# Gradle Build (testλ μ μΈ) | |
- name: Build with Gradle | |
run: ./gradlew build -x test | |
# λ컀 νλΈμ λ‘κ·ΈμΈ | |
- name: Docker Hub Login | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USER_NAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build Docker image | |
run: docker build -t ${{ secrets.DOCKER_USER_NAME }}/eatmate . | |
- name: Push Docker image | |
run: docker push ${{ secrets.DOCKER_USER_NAME }}/eatmate | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
if: github.event_name == 'push' | |
steps: | |
- 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: Get Public IP | |
id: ip | |
uses: haythem/[email protected] | |
- name: Add GitHub Actions IP to Security Group | |
run: | | |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 | |
- name: Deploy to EC2 | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.EC2_USER }} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
port: 22 | |
script: | | |
EXISTING_CONTAINER_ID=$(sudo docker ps -q -f "publish=8080" -f "status=running") | |
if [ ! -z "$EXISTING_CONTAINER_ID" ]; then | |
sudo docker stop $EXISTING_CONTAINER_ID | |
sudo docker rm $EXISTING_CONTAINER_ID | |
fi | |
EXISTING_CONTAINER_ID=$(sudo docker ps -q -f "status=exited") | |
if [ ! -z "$EXISTING_CONTAINER_ID" ]; then | |
sudo docker rm $EXISTING_CONTAINER_ID | |
fi | |
sudo docker pull ${{ secrets.DOCKER_USER_NAME }}/eatmate | |
sudo docker run --name spring -d -p 8080:8080 -e TZ=Asia/Seoul ${{ secrets.DOCKER_USER_NAME }}/eatmate | |
sudo docker image prune -a -f | |
debug: true # Enable debugging output | |
- name: Remove GitHub Actions IP From Security Group | |
run: | | |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 | |