Skip to content

Commit

Permalink
Merge pull request #66 from 80000Coding/feat/65
Browse files Browse the repository at this point in the history
✨ CD Pipeline 구축
  • Loading branch information
psychology50 authored Feb 12, 2024
2 parents 77c1a96 + 228e478 commit fa05f98
Showing 1 changed file with 55 additions and 6 deletions.
61 changes: 55 additions & 6 deletions .github/workflows/develop-publish.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
name: Publish Docker Hub
name: Continuous Deployment

on:
push:
tags:
- 'v*.*.*'
branches: ["dev"]
workflow_dispatch:
inputs:
logLevel:
description: "Log level"
required: true
default: "warning"
type: choice
options:
- info
- warning
- error
environment:
description: "Environment"
required: false
type: environment

permissions:
contents: read

jobs:
docker:
Expand All @@ -18,22 +35,54 @@ jobs:
with:
java-version: '17'
distribution: 'adopt'

- name: set version from on push tags
run: |
TAG=${{ github.event.ref }}
VERSION=${TAG#refs/tags/}
echo "VERSION=${VERSION}" >> $GITHUB_ENV
- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: build docker
run: ./gradlew bootBuildImage --imageName=$REPO

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Publish Docker Image
run: |
docker push $REPO
docker tag $REPO $REPO:${{ env.VERSION }}
docker push $REPO:${{ env.VERSION }}
docker push $REPO:latest
- name: Get Github Actions IP
id: ip
uses: haythem/public-ip@v1.2

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_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: SSH Commands
uses: appleboy/ssh-action@v0.1.6
with:
host: ${{ secrets.AWS_SSH_HOST }}
username: ${{ secrets.AWS_SSH_USERNAME }}
password: ${{ secrets.AWS_SSH_PASSWORD }}
port: ${{ secrets.AWS_SSH_PORT }}
script: |
./run_80000coding_backend.sh
- 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 fa05f98

Please sign in to comment.