Skip to content

Commit

Permalink
feat: cd action μž‘μ„±
Browse files Browse the repository at this point in the history
  • Loading branch information
punchdrunkard committed Jul 29, 2024
1 parent 8ec1c6c commit b845b74
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Java CI/CD Pipeline with Gradle and Docker

on:
push:
branches: [ "main" ]
pull_request: # TODO: ν…ŒμŠ€νŠΈμš©, mergeμ‹œ μ‚­μ œν•˜κΈ°
branches: [ "main" ]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Get Github Actions IP
id: ip
uses: haythem/[email protected]

- 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: 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: checkout
uses: actions/checkout@v3

- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'

## create application-database.yaml -> TODO: DB 연동할 λ•Œ ν™œμ„±ν™”, submodule μ‚¬μš©
# - name: make application-database.yaml
# run: |
# ## create application-database.yaml
# cd ./src/main/resources
#
# # application-database.yaml 파일 생성
# touch ./application-database.yaml
#
# # GitHub-Actions μ—μ„œ μ„€μ •ν•œ 값을 application-database.yaml νŒŒμΌμ— μ“°κΈ°
# echo "${{ secrets.DATABASE }}" >> ./application-database.yaml
# shell: bash

- name: Build with Gradle
run: ./gradlew bootJar

- name: web docker build and push
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t ${{ secrets.DOCKER_REPO }}/fiesta-web .
docker push ${{ secrets.DOCKER_REPO }}/fiesta-web
## docker compose up
- name: executing remote ssh commands using password
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ubuntu
key: ${{ secrets.KEY }}
script: |
sudo docker rm -f $(docker ps -qa)
sudo docker pull ${{ secrets.DOCKER_REPO }}/fiesta-web
docker-compose up -d
docker image prune -f
- 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

0 comments on commit b845b74

Please sign in to comment.