使用github actions CICD到aws的ecs服务

使用github actions CICD to aws ecs服务

本文记录从头搭建一个简单web后端环境配置gihub actions到最终运行至aws ecs集群。

参考文档

  1. github actions官方文档
  2. aws ecs搭建官方文档
  3. aws task definition参数官方文档

Step 1 本地项目配置

  1. 新建一个spring项目,并添加一个心跳接口用以校验服务是否正常启动。
    在这里插入图片描述

  2. 根据github官方文档中提供的demo示例添加workflow文件,因为github actions会自动扫描./github/workflows/目录下的workflow文件,所以命名随意,我这里命名未CICD.yml。以下是CICD.yml内容。
    文件中的on:触发操作需要按照自己项目需求修改,文件中的env配置信息需要按照自己项目需求修改

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.

name: Deploy to Amazon ECS

on:
  push:
    branches:
      - yourBranch                     # push to yourBranch will toggle this workflow

env:
  AWS_REGION: yourAwsRegion                 # set this to your preferred AWS region, e.g. us-west-1
  ECR_REPOSITORY: yourEcrRepository           # set this to your Amazon ECR repository name
  ECS_SERVICE: yourEcsService                 # set this to your Amazon ECS service name
  ECS_CLUSTER: yourEcsCluster                 # set this to your Amazon ECS cluster name
  ECS_TASK_DEFINITION: yourTaskDefinitionFileName # set this to the path to your Amazon ECS task definition
  # file, e.g. task-definition.json
  CONTAINER_NAME: yourContainerName
  # set this to the name of the container in the
  # containerDefinitions section of your task definition

jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest
    environment: production

    steps:
      - name: Checkout
        u
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值