Skip to content

Commit

Permalink
Merge pull request #5 from Footprints-Plan/cicd-test
Browse files Browse the repository at this point in the history
[FP-75] Feat: 다중배포환경 세팅
  • Loading branch information
tjdgns8439 authored Aug 27, 2024
2 parents 0768c8a + 7932f33 commit ffabe7b
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 47 deletions.
31 changes: 24 additions & 7 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: Continuous Integration
on:
push:
branches: ["main"]
paths-ignore:
- 'xinfra/eks/**'

permissions:
id-token: write
Expand Down Expand Up @@ -57,8 +59,8 @@ jobs:
- name: Set Spring Image Environment Variable
run: |
echo "SPRING_IMAGE=${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.REPOSITORY }}${{ env.IMAGE_TAG }}" >> ${GITHUB_ENV}
echo "LATEST_IMAGE=${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.REPOSITORY }}:latest" >> ${GITHUB_ENV}
echo "PROD_IMAGE=${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.REPOSITORY }}${{ env.IMAGE_TAG }}-prod" >> ${GITHUB_ENV}
echo "DEV_IMAGE=${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.REPOSITORY }}${{ env.IMAGE_TAG }}-dev" >> ${GITHUB_ENV}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
Expand All @@ -72,11 +74,26 @@ jobs:
uses: aws-actions/amazon-ecr-login@v2


- name: Build Image
run: docker build --no-cache -t ${{ env.SPRING_IMAGE }} -f ./xinfra/docker/Dockerfile .
- name: Build Prod Image
run: docker build --no-cache -t ${{ env.PROD_IMAGE }} -f ./xinfra/docker/DockerfileProd .

- name: Build Dev Image
run: docker build --no-cache -t ${{ env.DEV_IMAGE }} -f ./xinfra/docker/DevDockerfileDev .

- name: Push to ECR
run: |
docker push ${{ env.SPRING_IMAGE }}
docker tag ${{ env.SPRING_IMAGE }} ${{ env.LATEST_IMAGE }}
docker push ${{ env.LATEST_IMAGE }}
docker push ${{ env.PROD_IMAGE }}
docker push ${{ env.DEV_IMAGE }}
- name: Update Kustomize with new images
run: |
sed -i "s|image:.*-prod|image: ${{ env.PROD_IMAGE }}|g" ./xinfra/eks/overlays/prod/patch.yaml
sed -i "s|image:.*-dev|image: ${{ env.DEV_IMAGE }}|g" ./xinfra/eks/overlays/dev/patch.yaml
- name: Commit and Push Changes
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Actions"
git add ./xinfra/eks/overlays/prod/patch.yaml ./xinfra/eks/overlays/dev/patch.yaml
git commit -m "Update kustomization files with new image tags"
git push origin ${{ github.ref }}
2 changes: 1 addition & 1 deletion config
10 changes: 10 additions & 0 deletions xinfra/docker/DockerfileDev
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM eclipse-temurin:17-jre-jammy
LABEL authors="tjdgns8439"

WORKDIR /app

COPY build/libs/*.jar /app/app.jar

EXPOSE 8080

ENTRYPOINT java -jar "-Dspring.profiles.active=dev" /app/app.jar
10 changes: 10 additions & 0 deletions xinfra/docker/DockerfileProd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM eclipse-temurin:17-jre-jammy
LABEL authors="tjdgns8439"

WORKDIR /app

COPY build/libs/*.jar /app/app.jar

EXPOSE 8080

ENTRYPOINT java -jar "-Dspring.profiles.active=prod" /app/app.jar
39 changes: 0 additions & 39 deletions xinfra/eks/app-deploy.yaml

This file was deleted.

22 changes: 22 additions & 0 deletions xinfra/eks/base/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: springapp-deploy
spec:
replicas: 3
strategy:
type: RollingUpdate
selector:
matchLabels:
app: springapp-pod
template:
metadata:
labels:
app: springapp-pod
spec:
containers:
- name: springapp-pod
imagePullPolicy: Always
image: springapp-pod
ports:
- containerPort: 80
13 changes: 13 additions & 0 deletions xinfra/eks/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

namespace: springapp
commonLabels:
app: springapp-pod

images:
- name: springapp-pod

resources:
- ./deployment.yaml
- ./service.yaml
11 changes: 11 additions & 0 deletions xinfra/eks/base/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: springapp-svc
spec:
selector:
app: springapp-pod
ports:
- port: 80
targetPort: 8080
type: ClusterIP
10 changes: 10 additions & 0 deletions xinfra/eks/overlays/dev/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: springapp-dev
commonLabels:
env: dev
resources:
- ../../base
nameSuffix: -dev
patchesStrategicMerge:
- patch.yaml
10 changes: 10 additions & 0 deletions xinfra/eks/overlays/dev/patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: springapp-deploy
spec:
template:
spec:
containers:
- name: springapp-deploy
image: 992382409375.dkr.ecr.ap-northeast-2.amazonaws.com/footprints-dev:latest
10 changes: 10 additions & 0 deletions xinfra/eks/overlays/prod/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: springapp-prod
commonLabels:
env: prod
resources:
- ../../base
nameSuffix: -prod
patchesStrategicMerge:
- patch.yaml
10 changes: 10 additions & 0 deletions xinfra/eks/overlays/prod/patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: springapp-deploy
spec:
template:
spec:
containers:
- name: springapp-deploy
image: 992382409375.dkr.ecr.ap-northeast-2.amazonaws.com/footprints-prod:latest

0 comments on commit ffabe7b

Please sign in to comment.