LiJell's 성장기

Inject the App Version into the environment file during the EC2 CI/CD process 본문

Cloud

Inject the App Version into the environment file during the EC2 CI/CD process

All_is_LiJell 2024. 11. 12. 18:08
반응형

In the project, the environment file is currently updated every time right before deploying to the QA or Prod environment, specifically to change the APP_VERSION value. To avoid unnecessary updates to the environment files, I suggested injecting the app version into the environment file during the CI/CD process.

Method

The backend deployment consists of two sections: GitHub Workflows and AWS Code Series. When code is merged into the GitHub repository, GitHub Workflows are triggered. During the GitHub Action, I will inject the APP_VERSION from the Jira release version into deploy.sh, which is used in the Code Series. The first code block is part of deploy.sh, and the aws s3 sync command will be replaced as shown in the second code block. Then, ENV_FILE and APP_VERSION will be replaced in the GitHub Action just like second code block so that the APP_VERSION is applied during the CI/CD process.

1.

#!/bin/bash

# get environment file from s3
aws s3 sync

ENV_FILE=
APP_VERSION=
sed -i "/^APP_VERSION=/ s|.*|${APP_VERSION}|" /home/ubuntu/.project/${ENV_FILE}

...

2.

 - name: Modify deploy script to get and refine env file
        run: |
          # Define the bucket
          bucket="${{ needs.init.outputs.env_bucket }}"
          
          env_script="aws s3 sync s3://${bucket}/latest/ /home/ubuntu/.project/"

          sed -i "/^aws s3 sync/ s|.*|${env_script}|" ./codedeploy/deploy.sh

          # app version 
          app_version="${{ inputs.release_version }}"
          sed -i "/^APP_VERSION=/ s|.*|APP_VERSION=${app_version}|" ./codedeploy/deploy.sh

          # env file name
          if [ "${{ inputs.target_branch }}" == "production" ]; then
            env_file="production.env"
          else
            env_file="qa.env"
          fi

          sed -i "/^ENV_FILE=/ s|.*|ENV_FILE=${env_file}|" ./codedeploy/deploy.sh
반응형
Comments