From ab3bc2fe54ff1ef8270f5428bc882f276c7e8d34 Mon Sep 17 00:00:00 2001 From: Tsubasa SEKIGUCHI Date: Sat, 9 May 2026 09:19:58 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B9=E3=83=86=E3=83=BC=E3=82=B8=E3=83=B3?= =?UTF-8?q?=E3=82=B0=E7=92=B0=E5=A2=83=E3=81=B8=E3=81=AE=E3=83=87=E3=83=97?= =?UTF-8?q?=E3=83=AD=E3=82=A4=E3=83=AF=E3=83=BC=E3=82=AF=E3=83=95=E3=83=AD?= =?UTF-8?q?=E3=83=BC=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../deploy_ecs_staging_stationapi.yml | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 .github/workflows/deploy_ecs_staging_stationapi.yml diff --git a/.github/workflows/deploy_ecs_staging_stationapi.yml b/.github/workflows/deploy_ecs_staging_stationapi.yml new file mode 100644 index 00000000..a2a6c416 --- /dev/null +++ b/.github/workflows/deploy_ecs_staging_stationapi.yml @@ -0,0 +1,75 @@ +name: Deploy StationAPI to Staging Environment on Amazon ECS + +on: + workflow_dispatch: + push: + branches: + - master + paths: + - ".sqlx/**" + - "data/**" + - "scripts/**" + - "stationapi/**" + - "Cargo.lock" + - "Cargo.toml" + +env: + AWS_REGION: ${{ secrets.AWS_REGION }} + ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }} + ECS_SERVICE: ${{ secrets.ECS_SERVICE }} + ECS_CLUSTER: ${{ secrets.ECS_CLUSTER }} + ECS_TASK_DEFINITION: ${{ secrets.ECS_TASK_DEFINITION }} + CONTAINER_NAME: ${{ secrets.ECS_CONTAINER_NAME }} + +jobs: + deploy: + name: Deploy StationAPI Staging + runs-on: self-hosted + environment: staging + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ env.AWS_REGION }} + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v2 + + - name: Build, tag, and push image to Amazon ECR + id: build-image + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + IMAGE_TAG: ${{ github.sha }} + run: | + docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f ./docker/api/Dockerfile . + docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT + + - name: Download task definition + run: | + aws ecs describe-task-definition --task-definition ${{ env.ECS_TASK_DEFINITION }} --query taskDefinition > task-definition.json + + - name: Fill in the new image ID in the Amazon ECS task definition + id: task-def + uses: aws-actions/amazon-ecs-render-task-definition@v1 + with: + task-definition: task-definition.json + container-name: ${{ env.CONTAINER_NAME }} + image: ${{ steps.build-image.outputs.image }} + + - name: Deploy Amazon ECS task definition + uses: aws-actions/amazon-ecs-deploy-task-definition@v2 + with: + task-definition: ${{ steps.task-def.outputs.task-definition }} + service: ${{ env.ECS_SERVICE }} + cluster: ${{ env.ECS_CLUSTER }} + wait-for-service-stability: true