Skip to content

Commit

Permalink
chore: microservices
Browse files Browse the repository at this point in the history
  • Loading branch information
downfa11 committed Jul 3, 2024
1 parent 94e2053 commit ccc09c2
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
name: Docker Image CI

env:
MODULES: |
business-service
dedicated-service
membership-service
MODULE: business-service
BUILD_ID: ${{ github.sha }}
HELM_VALUE: business-service-chart/values-dev.yaml
HELM_BRANCH: dev

on:
push:
branches: ["main"]
branches: [ "main" ]
pull_request:
branches: ["main"]
branches: [ "main" ]

jobs:

build:

runs-on: ubuntu-latest

steps:
Expand All @@ -24,33 +24,24 @@ jobs:
run: chmod +x ./gradlew

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
uses: aws-actions/configure-aws-credentials@v4 # More information on this action can be found below in the 'AWS Credentials' section
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-access-key-id: ${{secrets.AWS_ACCESS_KEY_ID}}
aws-secret-access-key: ${{secrets.AWS_SECRET_ACCESS_KEY}}
aws-region: ap-northeast-2

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build, tag, and push docker images to Amazon ECR
- name: Build, tag, and push docker image to Amazon ECR
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: resistance-business
IMAGE_TAG: ${{ github.sha }}
run: |
for MODULE in $MODULES; do
HELM_VALUE=${MODULE}-chart/values-dev.yaml
ECR_REPOSITORY="resistance-$(echo $MODULE | cut -d '-' -f 1)"
echo "Building and pushing Docker image for $MODULE"
envsubst < Dockerfile.template | docker build -t $REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f - --build-arg MODULE=$MODULE .
docker push $REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "Updating Helm chart for $MODULE"
yq -i '.image.tag = "'$IMAGE_TAG'"' helm-chart/$HELM_VALUE
done
envsubst < Dockerfile.template | docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG -f - .
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG
- name: Checkout Helm Repository
uses: actions/checkout@v3
Expand All @@ -60,13 +51,19 @@ jobs:
ref: main
ssh-key: ${{ secrets.HELM_CHARTS_REPO_KEY }}

- name: Change Image tag of the Helm value
uses: mikefarah/[email protected]
with:
cmd: yq -i '.image.tag = "${{ env.BUILD_ID }}"' helm-chart/${{ env.HELM_VALUE }}


- name: Commit and Push HELM changes
run: |
cd helm-chart
git config --local user.email "[email protected]"
git config --local user.name "downfa11"
git add .
git commit -m "Commit HELM changes: ${{ github.sha }}"
git commit -m "Commit HELM changes: ${{ env.ECR_REPOSITORY }}:${{ env.BUILD_ID }}"
current_branch=$(git branch --show-current)
git checkout -b ${{ env.HELM_BRANCH }} && git merge ${current_branch}
git push --force origin ${{ env.HELM_BRANCH }}
git push --force origin ${{ env.HELM_BRANCH }}
69 changes: 69 additions & 0 deletions .github/workflows/dedicated-canary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Docker Image CI

env:
MODULE: dedicated-service
BUILD_ID: ${{ github.sha }}
HELM_VALUE: dedicated-service-chart/values-dev.yaml
HELM_BRANCH: dev

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4 # More information on this action can be found below in the 'AWS Credentials' section
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: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build, tag, and push docker image to Amazon ECR
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: resistance-dedicated
IMAGE_TAG: ${{ github.sha }}
run: |
envsubst < Dockerfile.template | docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG -f - .
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG
- name: Checkout Helm Repository
uses: actions/checkout@v3
with:
repository: downfa11/k8s-Devops
path: helm-chart
ref: main
ssh-key: ${{ secrets.HELM_CHARTS_REPO_KEY }}

- name: Change Image tag of the Helm value
uses: mikefarah/[email protected]
with:
cmd: yq -i '.image.tag = "${{ env.BUILD_ID }}"' helm-chart/${{ env.HELM_VALUE }}


- name: Commit and Push HELM changes
run: |
cd helm-chart
git config --local user.email "[email protected]"
git config --local user.name "downfa11"
git add .
git commit -m "Commit HELM changes: ${{ env.ECR_REPOSITORY }}:${{ env.BUILD_ID }}"
current_branch=$(git branch --show-current)
git checkout -b ${{ env.HELM_BRANCH }} && git merge ${current_branch}
git push --force origin ${{ env.HELM_BRANCH }}
69 changes: 69 additions & 0 deletions .github/workflows/membership-canary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Docker Image CI

env:
MODULE: membership-service
BUILD_ID: ${{ github.sha }}
HELM_VALUE: membership-service-chart/values-dev.yaml
HELM_BRANCH: dev

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4 # More information on this action can be found below in the 'AWS Credentials' section
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: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build, tag, and push docker image to Amazon ECR
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: resistance-membership
IMAGE_TAG: ${{ github.sha }}
run: |
envsubst < Dockerfile.template | docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG -f - .
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG
- name: Checkout Helm Repository
uses: actions/checkout@v3
with:
repository: downfa11/k8s-Devops
path: helm-chart
ref: main
ssh-key: ${{ secrets.HELM_CHARTS_REPO_KEY }}

- name: Change Image tag of the Helm value
uses: mikefarah/[email protected]
with:
cmd: yq -i '.image.tag = "${{ env.BUILD_ID }}"' helm-chart/${{ env.HELM_VALUE }}


- name: Commit and Push HELM changes
run: |
cd helm-chart
git config --local user.email "[email protected]"
git config --local user.name "downfa11"
git add .
git commit -m "Commit HELM changes: ${{ env.ECR_REPOSITORY }}:${{ env.BUILD_ID }}"
current_branch=$(git branch --show-current)
git checkout -b ${{ env.HELM_BRANCH }} && git merge ${current_branch}
git push --force origin ${{ env.HELM_BRANCH }}

0 comments on commit ccc09c2

Please sign in to comment.