使用github actions CICD to aws ecs服务
本文记录从头搭建一个简单web后端环境配置gihub actions到最终运行至aws ecs集群。
参考文档
:
Step 1 本地项目配置
-
新建一个spring项目,并添加一个心跳接口用以校验服务是否正常启动。
-
根据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