Skip to content

feat: cd μž‘μ„± #1

feat: cd μž‘μ„±

feat: cd μž‘μ„± #1

Workflow file for this run

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