File tree 4 files changed +69
-0
lines changed
priv/templates/nimble_template/.github/workflows
4 files changed +69
-0
lines changed Original file line number Diff line number Diff line change @@ -51,4 +51,14 @@ defmodule NimbleTemplate.Addons.Github do
51
51
52
52
project
53
53
end
54
+
55
+ @ impl true
56
+ def do_apply ( % Project { } = project , opts ) when opts . github_action_deploy_aws_ecs do
57
+ Generator . copy_file ( [
58
+ { :eex , ".github/workflows/deploy_to_aws_ecs.yml.eex" ,
59
+ ".github/workflows/deploy_to_aws_ecs.yml" }
60
+ ] )
61
+
62
+ project
63
+ end
54
64
end
Original file line number Diff line number Diff line change @@ -9,4 +9,7 @@ defmodule NimbleTemplate.GithubHelper do
9
9
10
10
def generate_github_action? ( ) ,
11
11
do: Mix . shell ( ) . yes? ( "\n Do you want to generate the Github Action workflow?" )
12
+
13
+ def generate_github_action_deploy_aws? ( ) ,
14
+ do: Mix . shell ( ) . yes? ( "\n Do you want to generate the Github Action to deploy to AWS ECS?" )
12
15
end
Original file line number Diff line number Diff line change @@ -38,6 +38,9 @@ defmodule NimbleTemplate.Phoenix.Template do
38
38
39
39
if generate_github_action? ( ) ,
40
40
do: Addons.Github . apply ( project , % { github_action: true } )
41
+
42
+ if generate_github_action_deploy_aws? ( ) ,
43
+ do: Addons.Github . apply ( project , % { github_action_deploy_aws_ecs: true } )
41
44
end
42
45
43
46
if install_addon_prompt? ( "Oban" ) , do: Addons.Oban . apply ( project )
Original file line number Diff line number Diff line change
1
+ name: Deploy to Amazon ECS
2
+
3
+ on:
4
+ workflow_run:
5
+ branches:
6
+ - develop
7
+ types:
8
+ - completed
9
+ workflow_dispatch:
10
+
11
+ env:
12
+ DOCKER_REGISTRY_HOST: ${{ secrets.ECR_REGISTRY_HOST }}
13
+ DOCKER_IMAGE: ${{ secrets.STAGING_ECR_REPO }}
14
+ ECS_CLUSTER: ${{ secrets.STAGING_ECS_CLUSTER }}
15
+ ECS_SERVICE: ${{ secrets.STAGING_ECS_SERVICE }}
16
+ BRANCH_TAG: latest
17
+
18
+ jobs:
19
+ deploy:
20
+ name: Deploy to ECS
21
+ runs-on: ubuntu-latest
22
+ steps:
23
+ - name: Cancel previous runs
24
+
25
+ with:
26
+ access_token: ${{ github.token }}
27
+
28
+ - name: Configure AWS credentials
29
+ uses: aws-actions/configure-aws-credentials@v1
30
+ with:
31
+ aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
32
+ aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
33
+ aws-region: ${{ secrets.AWS_REGION }}
34
+
35
+
36
+
37
+ - name: Login to Amazon ECR
38
+ id: login-ecr
39
+ uses: aws-actions/amazon-ecr-login@v1
40
+
41
+ - name: Build, tag, and push image to Amazon ECR
42
+ id: build-image
43
+ env:
44
+ ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
45
+ ECR_REPOSITORY: $ECR_REPOSITORY
46
+ IMAGE_TAG: ${{ github.sha }}
47
+ run: |
48
+ docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
49
+ docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
50
+ echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
51
+
52
+ - name: Update Service
53
+ run: aws ecs update-service --cluster $ECS_CLUSTER --service $ECS_SERVICE --force-new-deployment
You can’t perform that action at this time.
0 commit comments