Skip to content

Commit

Permalink
Merge pull request #2 from 2024-Iris/deploy
Browse files Browse the repository at this point in the history
인프라 구성 1단계 및 CI/CD 테스트
  • Loading branch information
dokkisan authored Apr 18, 2024
2 parents 36f5911 + b010e4a commit 565cb9d
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 0 deletions.
110 changes: 110 additions & 0 deletions .github/workflows/ecs_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Deploy to Amazon ECS

on:
push:
branches: [ "deploy" ]

env:
AWS_REGION: ${{ secrets.AWS_REGION }}
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
ECS_SERVICE: ${{ secrets.ECS_SERVICE }}
ECS_CLUSTER: ${{ secrets.ECS_CLUSTER }}
ECS_TASK_DEFINITION: ${{ secrets.ECS_TASK_DEFINITION }}
CONTAINER_NAME: ${{ secrets.CONTAINER_NAME }}

permissions:
contents: read

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'recursive'
token: ${{ secrets.GH_ISSUEFY_ROY_TOKEN }}

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Semantic Release
run: |
OUTPUT=$(npx semantic-release --no-ci)
echo "$OUTPUT"
VERSION=$(echo "$OUTPUT" | grep -oP 'Published release \K[0-9.]+')
if [ ! -z "$VERSION" ]; then
echo "SEMANTIC_VERSION=$VERSION" >> $GITHUB_ENV
else
echo "Error: SEMANTIC_VERSION not extracted" && exit 1
fi
env:
GH_TOKEN: ${{ secrets.GH_ISSUEFY_ROY_TOKEN }}

- name: Overwrite application.yml with submodule version
run: |
cp submodules/application.yml src/main/resources/application.yml
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
java-package: jdk
architecture: 'x64'

- name: Build with Gradle
run: |
cd ${{ github.workspace }}
chmod +x gradlew
./gradlew clean build
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
mask-password: 'true'

- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$SEMANTIC_VERSION -f dockerfile_was .
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$SEMANTIC_VERSION $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$SEMANTIC_VERSION
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$SEMANTIC_VERSION" >> $GITHUB_ENV
- name: Get latest ECS task definition
id: get-latest-task-def
run: |
TASK_DEF=$(aws ecs describe-services --cluster ${ECS_CLUSTER} --services ${ECS_SERVICE} --region ${AWS_REGION} --query "services[0].taskDefinition" --output text)
aws ecs describe-task-definition --task-definition $TASK_DEF --region ${AWS_REGION} --query "taskDefinition" --output json > task-definition.json
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ env.image }}

- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "submodules"]
path = submodules
url = https://github.com/2024-Iris/issuefy-spring-submodule.git
4 changes: 4 additions & 0 deletions dockerfile_was
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM openjdk:17.0.1-jdk-slim
ARG JAR_FILE=build/libs/issuefy-0.0.1-SNAPSHOT.jar
COPY ${JAR_FILE} issuefy-was.jar
ENTRYPOINT ["java","-jar","/issuefy-was.jar"]
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "issuefy-spring",
"version": "0.0.0-development",
"repository": {
"type": "git",
"url": "git+https://github.com/2024-Iris/issuefy-spring.git"
},
"release": {
"branches": ["main", "deploy"],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/github"
]
}
}
15 changes: 15 additions & 0 deletions src/main/java/site/iris/issuefy/StatusController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package site.iris.issuefy;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class StatusController {

@GetMapping("/status")
@ResponseBody
public String status() {
return "service is running!!";
}
}
1 change: 1 addition & 0 deletions submodules
Submodule submodules added at 9b329e

0 comments on commit 565cb9d

Please sign in to comment.