Skip to content

Commit 4ce9eab

Browse files
authored
Merge pull request #2085 from github/deployment-guides/add-gke
Add GKE, Amazon ECS, and Azure App Service deployment guides
2 parents 7266455 + 3aeac43 commit 4ce9eab

4 files changed

Lines changed: 450 additions & 0 deletions

File tree

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
---
2+
title: Deploying to Amazon Elastic Container Service
3+
intro: You can deploy to Amazon Elastic Container Service (ECS) as part of your continuous deployment (CD) workflows.
4+
product: '{% data reusables.gated-features.actions %}'
5+
versions:
6+
free-pro-team: '*'
7+
enterprise-server: '>=2.22'
8+
---
9+
10+
{% data reusables.actions.enterprise-beta %}
11+
{% data reusables.actions.enterprise-github-hosted-runners %}
12+
13+
### Introduction
14+
15+
This guide explains how to use {% data variables.product.prodname_actions %} to build a containerized application, push it to [Amazon Elastic Container Registry (ECR)](https://aws.amazon.com/ecr/), and deploy it to [Amazon Elastic Container Service (ECS)](https://aws.amazon.com/ecs/).
16+
17+
On every new release in your {% data variables.product.company_short %} repository, the {% data variables.product.prodname_actions %} workflow builds and pushes a new container image to Amazon ECR, and then deploys a new task definition to Amazon ECS.
18+
19+
### Prerequisites
20+
21+
Before creating your {% data variables.product.prodname_actions %} workflow, you will first need to complete the following setup steps for Amazon ECR and ECS:
22+
23+
1. Create an Amazon ECR repository to store your images.
24+
25+
For example, using [the AWS CLI](https://aws.amazon.com/cli/):
26+
27+
{% raw %}```bash{:copy}
28+
aws ecr create-repository \
29+
--repository-name MY_ECR_REPOSITORY \
30+
--region MY_AWS_REGION
31+
```{% endraw %}
32+
33+
Ensure that you use the same Amazon ECR repository name (represented here by `MY_ECR_REPOSITORY`) for the `ECR_REPOSITORY` variable in the workflow below.
34+
35+
Ensure that you use the same AWS region value for the `AWS_REGION` (represented here by `MY_AWS_REGION`) variable in the workflow below.
36+
37+
2. Create an Amazon ECS task definition, cluster, and service.
38+
39+
For details, follow the [Getting started wizard on the Amazon ECS console](https://us-east-2.console.aws.amazon.com/ecs/home?region=us-east-2#/firstRun), or the [Getting started guide](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/getting-started-fargate.html) in the Amazon ECS documentation.
40+
41+
Ensure that you note the names you set for the Amazon ECS service and cluster, and use them for the `ECS_SERVICE` and `ECS_CLUSTER` variables in the workflow below.
42+
43+
3. Store your Amazon ECS task definition as a JSON file in your {% data variables.product.company_short %} repository.
44+
45+
The format of the file should be the same as the output generated by:
46+
47+
{% raw %}```bash{:copy}
48+
aws ecs register-task-definition --generate-cli-skeleton
49+
```{% endraw %}
50+
51+
Ensure that you set the `ECS_TASK_DEFINITION` variable in the workflow below as the path to the JSON file.
52+
53+
Ensure that you set the `CONTAINER_NAME` variable in the workflow below as the container name in the `containerDefinitions` section of the task definition.
54+
55+
4. Create {% data variables.product.prodname_actions %} secrets named `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` to store the values for your Amazon IAM access key.
56+
57+
For more information on creating secrets for {% data variables.product.prodname_actions %}, see "[Encrypted secrets](/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository)."
58+
59+
See the documentation for each action used below for the recommended IAM policies for the IAM user, and methods for handling the access key credentials.
60+
61+
### Creating the workflow
62+
63+
Once you've completed the prerequisites, you can proceed with creating the workflow.
64+
65+
The following example workflow demonstrates how to build a container image and push it to Amazon ECR. It then updates the task definition with the new image ID, and deploys the task definition to Amazon ECS.
66+
67+
Ensure that you provide your own values for all the variables in the `env` key of the workflow.
68+
69+
{% raw %}
70+
```yaml{:copy}
71+
name: Deploy to Amazon ECS
72+
73+
on:
74+
release:
75+
types: [ created ]
76+
77+
env:
78+
AWS_REGION: MY_AWS_REGION # set this to your preferred AWS region, e.g. us-west-1
79+
ECR_REPOSITORY: MY_ECR_REPOSITORY # set this to your Amazon ECR repository name
80+
ECS_SERVICE: MY_ECS_SERVICE # set this to your Amazon ECS service name
81+
ECS_CLUSTER: MY_ECS_CLUSTER # set this to your Amazon ECS cluster name
82+
ECS_TASK_DEFINITION: MY_ECS_TASK_DEFINITION # set this to the path to your Amazon ECS task definition
83+
# file, e.g. .aws/task-definition.json
84+
CONTAINER_NAME: MY_CONTAINER_NAME # set this to the name of the container in the
85+
# containerDefinitions section of your task definition
86+
87+
defaults:
88+
run:
89+
shell: bash
90+
91+
jobs:
92+
deploy:
93+
name: Deploy
94+
runs-on: ubuntu-latest
95+
96+
steps:
97+
- name: Checkout
98+
uses: actions/checkout@v2
99+
100+
- name: Configure AWS credentials
101+
uses: aws-actions/configure-aws-credentials@v1
102+
with:
103+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
104+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
105+
aws-region: $AWS_REGION
106+
107+
- name: Login to Amazon ECR
108+
id: login-ecr
109+
uses: aws-actions/amazon-ecr-login@v1
110+
111+
- name: Build, tag, and push image to Amazon ECR
112+
id: build-image
113+
env:
114+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
115+
IMAGE_TAG: ${{ github.sha }}
116+
run: |
117+
# Build a docker container and
118+
# push it to ECR so that it can
119+
# be deployed to ECS.
120+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
121+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
122+
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_ENV
123+
124+
- name: Fill in the new image ID in the Amazon ECS task definition
125+
id: task-def
126+
uses: aws-actions/amazon-ecs-render-task-definition@v1
127+
with:
128+
task-definition: $ECS_TASK_DEFINITION
129+
container-name: $CONTAINER_NAME
130+
image: ${{ steps.build-image.outputs.image }}
131+
132+
- name: Deploy Amazon ECS task definition
133+
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
134+
with:
135+
task-definition: ${{ steps.task-def.outputs.task-definition }}
136+
service: $ECS_SERVICE
137+
cluster: $ECS_CLUSTER
138+
wait-for-service-stability: true
139+
```
140+
{% endraw %}
141+
142+
### Additional resources
143+
144+
For more information on the services used in these examples, see the following documentation:
145+
146+
* "[Security best practices in IAM](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)" in the Amazon AWS documentation.
147+
* Official AWS "[Configure AWS Credentials](https://github.com/aws-actions/configure-aws-credentials)" action.
148+
* Official AWS [Amazon ECR "Login"](https://github.com/aws-actions/amazon-ecr-login) action.
149+
* Official AWS [Amazon ECS "Render Task Definition"](https://github.com/aws-actions/amazon-ecs-render-task-definition) action.
150+
* Official AWS [Amazon ECS "Deploy Task Definition"](https://github.com/aws-actions/amazon-ecs-deploy-task-definition) action.
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
title: Deploying to Azure App Service
3+
intro: You can deploy to Azure App Service as part of your continuous deployment (CD) workflows.
4+
product: '{% data reusables.gated-features.actions %}'
5+
versions:
6+
free-pro-team: '*'
7+
enterprise-server: '>=2.22'
8+
---
9+
10+
{% data reusables.actions.enterprise-beta %}
11+
{% data reusables.actions.enterprise-github-hosted-runners %}
12+
13+
### Introduction
14+
15+
This guide explains how to use {% data variables.product.prodname_actions %} to build, test, and deploy an application to [Azure App Service](https://azure.microsoft.com/en-us/services/app-service/).
16+
17+
Azure App Service can run web apps in several languages, but this guide demonstrates deploying an existing Node.js project.
18+
19+
### Prerequisites
20+
21+
Before creating your {% data variables.product.prodname_actions %} workflow, you will first need to complete the following setup steps:
22+
23+
1. Create an Azure App Service plan.
24+
25+
For example, you can use the Azure CLI to create a new App Service plan:
26+
27+
```bash{:copy}
28+
az appservice plan create \
29+
--resource-group MY_RESOURCE_GROUP \
30+
--name MY_APP_SERVICE_PLAN \
31+
--is-linux
32+
```
33+
34+
In the command above, replace `MY_RESOURCE_GROUP` with your pre-existing Azure Resource Group, and `MY_APP_SERVICE_PLAN` with a new name for the App Service plan.
35+
36+
See the Azure documentation for more information on using the [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/):
37+
38+
* For authentication, see "[Sign in with Azure CLI](https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli)".
39+
* If you need to create a new resource group, see "[az group](https://docs.microsoft.com/en-us/cli/azure/group?view=azure-cli-latest#az_group_create)."
40+
41+
2. Create a web app.
42+
43+
For example, you can use the Azure CLI to create an Azure App Service web app with a node runtime:
44+
45+
```bash{:copy}
46+
az webapp create \
47+
--name MY_WEBAPP_NAME \
48+
--plan MY_APP_SERVICE_PLAN \
49+
--resource-group MY_RESOURCE_GROUP \
50+
--runtime "node|10.14"
51+
```
52+
53+
In the command above, replace the parameters with your own values, where `MY_WEBAPP_NAME` is a new name for the web app.
54+
55+
3. Configure an Azure publish profile and create an `AZURE_WEBAPP_PUBLISH_PROFILE` secret.
56+
57+
Generate your Azure deployment credentials using a publish profile. For more information, see "[Generate deployment credentials](https://docs.microsoft.com/en-us/azure/app-service/deploy-github-actions?tabs=applevel#generate-deployment-credentials)" in the Azure documentation.
58+
59+
In your {% data variables.product.prodname_dotcom %} repository, create a secret named `AZURE_WEBAPP_PUBLISH_PROFILE` that contains the contents of the publish profile. For more information on creating secrets, see "[Encrypted secrets](/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository)."
60+
61+
### Creating the workflow
62+
63+
Once you've completed the prerequisites, you can proceed with creating the workflow.
64+
65+
The following example workflow demonstrates how to build, test, and deploy the Node.js project to Azure App Service.
66+
67+
Ensure that you set `AZURE_WEBAPP_NAME` in the workflow `env` key to the name of the web app you created.
68+
69+
{% raw %}
70+
```yaml{:copy}
71+
on:
72+
release:
73+
types: [created]
74+
75+
env:
76+
AZURE_WEBAPP_NAME: MY_WEBAPP_NAME # set this to your application's name
77+
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
78+
NODE_VERSION: '10.x' # set this to the node version to use
79+
80+
jobs:
81+
build-and-deploy:
82+
name: Build and Deploy
83+
runs-on: ubuntu-latest
84+
steps:
85+
- uses: actions/checkout@v2
86+
87+
- name: Use Node.js ${{ env.NODE_VERSION }}
88+
uses: actions/setup-node@v1
89+
with:
90+
node-version: ${{ env.NODE_VERSION }}
91+
92+
- name: npm install, build, and test
93+
run: |
94+
# Build and test the project, then
95+
# deploy to Azure Web App.
96+
npm install
97+
npm run build --if-present
98+
npm run test --if-present
99+
100+
- name: 'Deploy to Azure WebApp'
101+
uses: azure/webapps-deploy@v2
102+
with:
103+
app-name: ${{ env.AZURE_WEBAPP_NAME }}
104+
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
105+
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
106+
```
107+
{% endraw %}
108+
109+
### Additional resources
110+
111+
The following resources may also be useful:
112+
113+
* For the original starter workflow, see [`azure.yml`](https://github.com/actions/starter-workflows/blob/master/ci/azure.yml) in the {% data variables.product.prodname_actions %} `starter-workflows` repository.
114+
* The action used to deploy the web app is the official Azure [`Azure/webapps-deploy`](https://github.com/Azure/webapps-deploy) action.
115+
* The "[Create a Node.js web app in Azure](https://docs.microsoft.com/en-us/azure/app-service/quickstart-nodejs)" quickstart in the Azure web app documentation demonstrates using VS Code with the [Azure App Service extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azureappservice).

0 commit comments

Comments
 (0)