chore: Adjusting CI (#317) #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build & Deploy Ahhachul One App | |
on: | |
push: | |
branches: | |
- main | |
# 추후 develop 브렌치는 제외 | |
- develop | |
paths: | |
- 'services/one-app/**' | |
env: | |
DEFAULT_NODE_VERSION: '20.13.0' | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check Out Repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Parse secrets from JSON | |
id: secrets | |
run: | | |
echo '${{ secrets.DEV_META_DATA }}' | jq -r 'to_entries | .[] | "echo \(.key)=\(.value) >> $GITHUB_ENV"' | bash | |
- name: Print AWS Region | |
run: echo "AWS_REGION is $AWS_REGION" | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ env.DEFAULT_NODE_VERSION }} | |
- name: Install dependencies | |
uses: ./.github/actions/pnpm-install | |
- name: Create .env file for one-app | |
run: | | |
echo '${{ secrets.DEV_ONE_APP_CONFIG }}' > config.json | |
cat config.json | jq -r 'to_entries[] | "\(.key)=\(.value)"' >> services/one-app/.env | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Log in to Amazon ECR Public | |
run: | | |
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin ${{ env.ECR_REPOSITORY_URI }} | |
- name: Build Docker image for one-app | |
run: docker build -t ${{ env.ECR_REPOSITORY_URI }}:one-app-latest -f Dockerfile . | |
- name: Push Docker image for one-app to Amazon ECR | |
run: docker push ${{ env.ECR_REPOSITORY_URI }}:one-app-latest | |
- name: Get the latest Task Definition ARN for one-app | |
id: task_definition_one_app | |
run: | | |
TASK_DEF_ARN=$(aws ecs describe-services \ | |
--cluster ${{ env.ECS_CLUSTER_NAME }} \ | |
--services ${{ env.ECS_SERVICE_NAME }} \ | |
--query 'services[0].taskDefinition' --output text) | |
echo "TASK_DEF_ARN_ONE_APP=$TASK_DEF_ARN" >> $GITHUB_ENV | |
- name: Generate appspec.yaml for one-app | |
run: | | |
cat <<EOF > ./appspec-one-app.yaml | |
version: 0.0 | |
Resources: | |
- TargetService: | |
Type: AWS::ECS::Service | |
Properties: | |
TaskDefinition: "$TASK_DEF_ARN_ONE_APP" | |
LoadBalancerInfo: | |
ContainerName: ${{ env.CONTAINER_NAME }} | |
ContainerPort: ${{ env.CONTAINER_PORT }} | |
CapacityProviderStrategy: | |
- CapacityProvider: "FARGATE_SPOT" | |
Base: 0 | |
Weight: 1 | |
EOF | |
- name: Create Codedeploy deployment for one-app | |
run: | | |
APPSPEC_CONTENT=$(cat appspec-one-app.yaml | jq -sR .) | |
aws deploy create-deployment \ | |
--application-name ${{ env.CODEDEPLOY_APP_NAME }} \ | |
--deployment-group-name ${{ env.CODEDEPLOY_DEPLOYMENT_GROUP }} \ | |
--deployment-config-name CodeDeployDefault.ECSAllAtOnce \ | |
--revision "{\"revisionType\":\"AppSpecContent\",\"appSpecContent\":{\"content\":$APPSPEC_CONTENT}}" |