-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(infra): rafactor re-server Terraform and Github Actions Files
- Loading branch information
Showing
7 changed files
with
474 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
name: RC - CD - Build Images | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
env: | ||
AWS_REGION: ap-northeast-2 | ||
ECS_CLUSTER: Codedang-Api | ||
|
||
permissions: # permissions to the job (for the OpenID Connection) | ||
id-token: write | ||
contents: read | ||
|
||
jobs: | ||
build-client-api: | ||
name: Build client-api image | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
role-to-assume: ${{ secrets.AWS_ROLE_FOR_ECR_PUSH_RC }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v2 | ||
|
||
- name: Build and push image | ||
uses: docker/build-push-action@v6 | ||
with: | ||
file: ./apps/backend/Dockerfile | ||
push: true | ||
build-args: | | ||
target=client | ||
app_env=production | ||
tags: ${{ steps.login-ecr.outputs.registry }}/codedang-client-api:latest | ||
|
||
build-admin-api: | ||
name: Build admin-api image | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
role-to-assume: ${{ secrets.AWS_ROLE_FOR_ECR_PUSH_RC }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v2 | ||
|
||
- name: Build and push image | ||
uses: docker/build-push-action@v6 | ||
with: | ||
file: ./apps/backend/Dockerfile | ||
push: true | ||
build-args: | | ||
target=admin | ||
app_env=production | ||
tags: ${{ steps.login-ecr.outputs.registry }}/codedang-admin-api:latest | ||
|
||
build-iris: | ||
name: Build iris Docker image | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Setup Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
role-to-assume: ${{ secrets.AWS_ROLE_FOR_ECR_PUSH_RC }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v2 | ||
|
||
- name: Build and push image (iris) | ||
uses: docker/build-push-action@v6 | ||
with: | ||
push: true | ||
context: '{{defaultContext}}:apps/iris' | ||
build-args: | | ||
app_env=production | ||
tags: ${{ steps.login-ecr.outputs.registry }}/codedang-iris:latest |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
name: RC - Deploy - Target | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
terraform_project: | ||
description: 'Select Terraform Project to Deploy' | ||
required: true | ||
type: choice | ||
options: | ||
- 'network' | ||
- 'storage' | ||
- 'codedang' | ||
|
||
env: | ||
AWS_REGION: ap-northeast-2 | ||
ECS_CLUSTER: Codedang-Api | ||
|
||
permissions: # permissions to the job (for the OpenID Connection) | ||
id-token: write | ||
contents: read | ||
|
||
jobs: | ||
rc-deploy-target-project: | ||
name: RC - Deploy Terraform targeted Project | ||
runs-on: ubuntu-latest | ||
environment: production | ||
defaults: | ||
run: | ||
shell: bash | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
role-to-assume: ${{ secrets.AWS_ROLE_FOR_DEPLOY_RC }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
|
||
- uses: hashicorp/setup-terraform@v3 | ||
with: | ||
terraform_version: 1.5.2 | ||
|
||
- name: Create Terraform variable file | ||
working-directory: ./apps/infra/rc/${{ github.event.inputs.terraform_project }} | ||
run: | | ||
echo "$TFVARS_RC" >> terraform.tfvars | ||
echo "$OAUTH_GITHUB" >> terraform.tfvars | ||
echo "$OAUTH_KAKAO" >> terraform.tfvars | ||
echo 'env = "rc"' >> terraform.tfvars | ||
env: | ||
TFVARS_RC: ${{ secrets.TFVARS_RC }} | ||
OAUTH_GITHUB: ${{ secrets.OAUTH_GITHUB }} | ||
OAUTH_KAKAO: ${{ secrets.OAUTH_KAKAO }} | ||
|
||
- name: Terraform Init | ||
working-directory: ./apps/infra/rc/${{ github.event.inputs.terraform_project }} | ||
run: terraform init -backend-config="bucket=codedang-tf-state-rc" | ||
|
||
- name: Terraform Plan | ||
working-directory: ./apps/infra/rc/${{ github.event.inputs.terraform_project }} | ||
run: terraform plan -input=false -out=plan.out | ||
|
||
- name: Terraform Apply | ||
working-directory: ./apps/infra/rc/${{ github.event.inputs.terraform_project }} | ||
run: terraform apply -input=false plan.out |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
name: RC - Deploy | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
env: | ||
AWS_REGION: ap-northeast-2 | ||
ECS_CLUSTER: Codedang-Api | ||
|
||
permissions: # permissions to the job (for the OpenID Connection) | ||
id-token: write | ||
contents: read | ||
|
||
jobs: | ||
rc-deploy-network: | ||
name: RC - Deploy Network | ||
runs-on: ubuntu-latest | ||
environment: production | ||
defaults: | ||
run: | ||
shell: bash | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
role-to-assume: ${{ secrets.AWS_ROLE_FOR_DEPLOY_RC }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
|
||
- uses: hashicorp/setup-terraform@v3 | ||
with: | ||
terraform_version: 1.5.2 | ||
|
||
- name: Create Terraform variable file | ||
working-directory: ./apps/infra/rc/network | ||
run: | | ||
echo 'env = "rc"' >> terraform.tfvars | ||
- name: Terraform Init | ||
working-directory: ./apps/infra/rc/network | ||
run: terraform init -backend-config="bucket=codedang-tf-state-rc" | ||
|
||
- name: Terraform Plan | ||
working-directory: ./apps/infra/rc/network | ||
run: terraform plan -input=false -out=plan.out | ||
|
||
- name: Terraform Apply | ||
working-directory: ./apps/infra/rc/network | ||
run: terraform apply -input=false plan.out | ||
|
||
rc-deploy-storage: | ||
name: RC - Deploy Storage | ||
runs-on: ubuntu-latest | ||
needs: [rc-deploy-network] | ||
environment: production | ||
defaults: | ||
run: | ||
shell: bash | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
role-to-assume: ${{ secrets.AWS_ROLE_FOR_DEPLOY_RC }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
|
||
- uses: hashicorp/setup-terraform@v3 | ||
with: | ||
terraform_version: 1.5.2 | ||
|
||
- name: Create Terraform variable file | ||
working-directory: ./apps/infra/rc/storage | ||
run: | | ||
echo 'env = "rc"' >> terraform.tfvars | ||
- name: Terraform Init | ||
working-directory: ./apps/infra/rc/storage | ||
run: terraform init -backend-config="bucket=codedang-tf-state-rc" | ||
|
||
- name: Terraform Plan | ||
working-directory: ./apps/infra/rc/storage | ||
run: terraform plan -input=false -out=plan.out | ||
|
||
- name: Terraform Apply | ||
working-directory: ./apps/infra/rc/storage | ||
run: terraform apply -input=false plan.out | ||
|
||
rc-deploy-codedang: | ||
name: RC - Deploy Codedang | ||
runs-on: ubuntu-latest | ||
needs: [rc-deploy-network, rc-deploy-storage] | ||
environment: production | ||
defaults: | ||
run: | ||
shell: bash | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
role-to-assume: ${{ secrets.AWS_ROLE_FOR_DEPLOY_RC }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
|
||
- uses: hashicorp/setup-terraform@v3 | ||
with: | ||
terraform_version: 1.5.2 | ||
|
||
- name: Create Terraform variable file | ||
working-directory: ./apps/infra/rc/codedang | ||
run: | | ||
echo "$TFVARS_RC" >> terraform.tfvars | ||
echo "$OAUTH_GITHUB" >> terraform.tfvars | ||
echo "$OAUTH_KAKAO" >> terraform.tfvars | ||
echo 'env = "rc"' >> terraform.tfvars | ||
env: | ||
TFVARS_RC: ${{ secrets.TFVARS_RC }} | ||
OAUTH_GITHUB: ${{ secrets.OAUTH_GITHUB }} | ||
OAUTH_KAKAO: ${{ secrets.OAUTH_KAKAO }} | ||
|
||
- name: Terraform Init | ||
working-directory: ./apps/infra/rc/codedang | ||
run: terraform init -backend-config="bucket=codedang-tf-state-rc" | ||
|
||
- name: Terraform Plan | ||
working-directory: ./apps/infra/rc/codedang | ||
run: terraform plan -input=false -out=plan.out | ||
|
||
- name: Terraform Apply | ||
working-directory: ./apps/infra/rc/codedang | ||
run: terraform apply -input=false plan.out |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: RC - Destroy - Target | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
terraform_project: | ||
description: 'Select Terraform Project to Destroy' | ||
required: true | ||
type: choice | ||
options: | ||
- 'network' | ||
- 'storage' | ||
- 'codedang' | ||
|
||
env: | ||
AWS_REGION: ap-northeast-2 | ||
ECS_CLUSTER: Codedang-Api | ||
|
||
permissions: # permissions to the job (for the OpenID Connection) | ||
id-token: write | ||
contents: read | ||
|
||
jobs: | ||
rc-destroy-terraform-target-project: | ||
name: RC - Destroy Terraform targeted Project | ||
runs-on: ubuntu-latest | ||
environment: production | ||
defaults: | ||
run: | ||
shell: bash | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: aws-actions/configure-aws-credentials@v4 | ||
with: | ||
role-to-assume: ${{ secrets.AWS_ROLE_FOR_DEPLOY_RC }} | ||
aws-region: ${{ env.AWS_REGION }} | ||
|
||
- uses: hashicorp/setup-terraform@v3 | ||
with: | ||
terraform_version: 1.5.2 | ||
|
||
- name: Create Terraform variable file | ||
working-directory: ./apps/infra/rc/${{ github.event.inputs.terraform_project }} | ||
run: | | ||
echo "$TFVARS_RC" >> terraform.tfvars | ||
echo "$OAUTH_GITHUB" >> terraform.tfvars | ||
echo "$OAUTH_KAKAO" >> terraform.tfvars | ||
echo 'env = "rc"' >> terraform.tfvars | ||
env: | ||
TFVARS_RC: ${{ secrets.TFVARS_RC }} | ||
OAUTH_GITHUB: ${{ secrets.OAUTH_GITHUB }} | ||
OAUTH_KAKAO: ${{ secrets.OAUTH_KAKAO }} | ||
|
||
- name: Destroy | ||
working-directory: ./apps/infra/rc/${{ github.event.inputs.terraform_project }} | ||
run: | | ||
terraform init -backend-config="bucket=codedang-tf-state-rc" | ||
terraform destroy -auto-approve |
Oops, something went wrong.