Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.

Commit fb4715c

Browse files
authored
Merge pull request #1 from githubtraining/test
Small change
2 parents 0a47315 + dffa197 commit fb4715c

15 files changed

+334
-49
lines changed

config.yml

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ before:
2020
# production-deployment-workflow: with the workflow file stub for production deploy from merge
2121
# staging-test: with a small change to the app that can be seen in staging
2222

23+
# we create a staging label that will be used later to test
24+
25+
- type: createLabel
26+
name: stage
27+
color: f87000
28+
2329
# PART 1: STAGING WORKFLOW
2430

2531
# Step 1: Configure a trigger based on labels
@@ -39,7 +45,7 @@ steps:
3945
- title: Configure a trigger based on labels
4046
description: Configure the workflow trigger based on an a label being added
4147
event: pull_request
42-
link: '{{ repoUrl }}/pulls/1'
48+
link: '{{ repoUrl }}/pull/1'
4349
actions:
4450
# We validate that trigger is correct
4551
#- type: gate
@@ -54,7 +60,7 @@ steps:
5460
- title: Choose the environment for AWS
5561
description: Choose the Ubuntu environment for our app
5662
event: pull_request
57-
link: '{{ repoUrl }}/pulls/1'
63+
link: '{{ repoUrl }}/pull/1'
5864
actions:
5965

6066
# We validate
@@ -69,24 +75,25 @@ steps:
6975
- title: Write the steps for the staging workflow
7076
description: Write the steps for the staging deployment workflow
7177
event: pull_request
72-
link: '{{ repoUrl }}/pulls/1'
78+
link: '{{ repoUrl }}/pull/1'
7379
actions:
7480

7581
# We validate
7682
#- type: gate
7783

78-
# We approve
79-
- type: createReview
80-
event: APPROVE
84+
# We remove branch protections
85+
- type: removeBranchProtection
86+
8187
# Step 4: Merge the staging workflow
8288
# We tell the user to merge
83-
body: 04_merge.md
89+
- type: respond
90+
with: 04_merge.md
8491

8592
# event: merge
8693
- title: Merge the staging workflow
8794
description: Merge this staging workflow pull request
8895
event: pull_request.closed
89-
link: '{{ repoUrl }}/pulls/1'
96+
link: '{{ repoUrl }}/pull/1'
9097
actions:
9198

9299
# we make sure it's merged
@@ -98,6 +105,8 @@ steps:
98105
right: closed
99106
- left: '%payload.pull_request.merged%'
100107

108+
# we reprotect master for the next PR
109+
- type: updateBranchProtection
101110

102111
# PART 2: AWS CONFIGURATION
103112

@@ -118,10 +127,10 @@ steps:
118127

119128
# event: responding with a comment
120129

121-
- title: Confirm AWS configuration
130+
- title: Confirm AWS S3 configuration
122131
description: Create an AWS account by the following specifications, and confirm here
123132
event: issue_comment.created
124-
link: '{{ repoUrl }}/pulls/2'
133+
link: '{{ repoUrl }}/pull/2'
125134
actions:
126135

127136
# Step 6: Enter environment variables
@@ -132,10 +141,10 @@ steps:
132141
with: 06_env-variables.md
133142

134143
# event: Respond with a comment
135-
- title: Enter environment variables
136-
description: Enter your AWS environment variables into this repository, and confirm here
144+
- title: Create and store environment variables
145+
description: Create your AWS IAM secrets and enter them in this repository
137146
event: issue_comment.created
138-
link: '{{ repoUrl }}/pulls/2'
147+
link: '{{ repoUrl }}/pull/2'
139148
actions:
140149

141150
# Validate if possible
@@ -147,12 +156,16 @@ steps:
147156
- type: respond
148157
with: 07_approve.md
149158

159+
# we formally request their approval
160+
- type: requestReviewFromRegistrant
161+
pullRequest: Configure AWS
162+
150163
# event: approval
151164

152165
- title: Approve pull request
153166
description: Approve pull request adding the aws-config.yml and sam-template.yml
154167
event: pull_request_review
155-
link: '{{ repoUrl }}/pulls/2'
168+
link: '{{ repoUrl }}/pull/2'
156169
actions:
157170

158171
# we make sure it's approved
@@ -191,7 +204,7 @@ steps:
191204
- title: Test the staging action
192205
description: Test the new action to deploy labeled pull requests to staging
193206
event: pull_request.labeled
194-
link: '{{ repoUrl }}/pulls/3'
207+
link: '{{ repoUrl }}/pull/3'
195208
actions:
196209

197210
# We need to prepare next PR for them where they write the prod deployment workflow
@@ -216,7 +229,7 @@ steps:
216229
- title: Write the production deployment trigger
217230
description: Write the production deployment trigger in the new workflow
218231
event: pull_request
219-
link: '{{ repoUrl }}/pulls/3'
232+
link: '{{ repoUrl }}/pull/3'
220233
actions:
221234

222235
# We validate
@@ -233,7 +246,7 @@ steps:
233246
- title: Choose the environment for AWS
234247
description: Commit the proper environment for AWS to the workflow file
235248
event: pull_request
236-
link: '{{ repoUrl }}/pulls/3'
249+
link: '{{ repoUrl }}/pull/3'
237250
actions:
238251

239252
# We validate
@@ -250,7 +263,7 @@ steps:
250263
- title: Write the steps for the production workflow
251264
description: Write the steps for the production deployment to the workflow file
252265
event: pull_request
253-
link: '{{ repoUrl }}/pulls/3'
266+
link: '{{ repoUrl }}/pull/3'
254267
actions:
255268

256269
# We validate
@@ -261,18 +274,19 @@ steps:
261274

262275
# Step 12: Merge this pull request and test the production deployment workflow
263276

264-
# We tell the user to merge, and that their merge will bring the action into `master`, and will also create a deployment into production
265-
- type: createReview
266-
body: 12_merge.md
267-
event: APPROVE
277+
# We remove branch protections
278+
- type: removeBranchProtection
268279

280+
# We tell the user to merge, and that their merge will bring the action into `master`, and will also create a deployment into production
281+
- type: respond
282+
with: 12_merge.md
269283

270284
# event: merge
271285

272-
- title: Merge this pull request
286+
- title: Merge the production workflow
273287
description: Merge this pull request and test the production deployment workflow
274288
event: pull_request.closed
275-
link: '{{ repoUrl }}/pulls/3'
289+
link: '{{ repoUrl }}/pull/3'
276290
actions:
277291

278292
# check that its merged

course-details.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
This course is about continuous delivery, or CD, with GitHub Actions. We create two workflows to deploy our app to an AWS S3 bucket automatically. CD is an important part of modern software development, and it has a big meaning. CD is the practice of delivering software faster and with higher quality. To do this, it takes many different practices, behaviors, and technologies.
2+
3+
In this course, we focus on workflows to deploy pull requests automatically to a staging environment, and to deploy all merged commits to production. In this course, you will:
4+
5+
- Create two workflow files
6+
- Configure AWS S3 for deployment
7+
- Use secrets to store tokens
8+
- Deploy to staging and production
9+
- Practice using GitHub Actions

responses/01_label-trigger.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,38 @@ We will be working with Continuous Delivery. We will...
66
- Use AWS configuration
77

88
Before you start, you should...
9-
- Introduction to GitHub
10-
- Continuous Integration with GitHub Actions
9+
- [Introduction to GitHub](https://lab.github.com/githubtraining/introduction-to-github)
10+
- [Continuous Integration with GitHub Actions](https://lab.github.com/githubtraining/set-up-continuous-integration-with-github-actions)
1111

1212
### What is Continuous Delivery?
1313

14-
I'll tell ya!
14+
According to [continuousdelivery.com](https://continuousdelivery.com/),
15+
16+
> Continuous Delivery is the ability to get changes of all types—including new features, configuration changes, bug fixes and experiments—into production, or into the hands of users, safely and quickly in a sustainable way.
17+
18+
A lot of things go into delivering "continuously". These things can range from culture and behavior to specific automation. In this course, we're going to focus on deployment automation.
1519

1620
## Step 1: Configure a trigger based on labels
1721

22+
During the `on` step, we define what should cause this workflow to run. In this case, we want the workflow to run whenever a label is applied to the pull request.
23+
1824
### :keyboard: Activity: Configure the workflow trigger based on an a label being added
25+
26+
1. Edit this file
27+
2. Change the name of the directory `CHANGETHIS` to `workflows`, so the title of this file with the path is `.github/workflows/staging-workflow.yml`
28+
3. Edit the contents of this file to trigger on a label
29+
30+
Your result should look like this:
31+
32+
```yml
33+
name: Staging deployment
34+
35+
on:
36+
pull_request:
37+
types: [labeled]
38+
39+
jobs:
40+
build:
41+
if: contains(github.event.pull_request.labels.*.name, 'stage')
42+
43+
```

responses/02_environment.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
# Choosing deployment environments
22

3-
We will be working with AWS for the deployment environment. AWS will do the work of creating the environment, but first, we need to tell it what we need. That happens in the `environment` section of the workflow file. You have many options here, but for our purpose, we will be using a basic Ubuntu environment for our Node.js application.
3+
We will be working with AWS for the deployment environment. AWS will do the work of creating the environment, but first, we need to tell it what we need. That happens in the `environment` section of the workflow file.
4+
5+
### What are the options?
6+
7+
You may want to choose a different environment based on your application. You can read more about [virtual environments for GitHub Actions](https://help.github.com/en/github/automating-your-workflow-with-github-actions/virtual-environments-for-github-actions) on GitHub Help.
48

59
## Step 2: Choose the environment for AWS
610

7-
### :keyboard: Activity: Choose the Ubuntu environment for our app
11+
For our `Node.js` application, we will be using a basic Ubuntu environment.
12+
13+
### :keyboard: Activity: Choose the Ubuntu environment for our app
14+
15+
```yml
16+
name: Staging deployment
17+
18+
on:
19+
pull_request:
20+
types: [labeled]
21+
22+
jobs:
23+
build:
24+
if: contains(github.event.pull_request.labels.*.name, 'stage')
25+
26+
runs-on: ubuntu-latest
27+
```

responses/03_workflow-steps.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,54 @@ So far, the workflow knows what the trigger is and what environment to run in. B
44

55
## Step 3: Write the steps for the staging workflow
66

7-
### :keyboard: Activity: Write the steps for the staging deployment workflow
7+
We won't be going into detail on the steps of this workflow, but it would be a good idea to check them out. You'll see that we're adding steps using existing actions for:
8+
9+
- `actions/checkout`
10+
- `Deploy to AWS`
11+
12+
### :keyboard: Activity: Write the steps for the staging deployment workflow
13+
14+
```yml
15+
name: Staging deployment
16+
17+
on:
18+
pull_request:
19+
types: [labeled]
20+
21+
jobs:
22+
build:
23+
if: contains(github.event.pull_request.labels.*.name, 'stage')
24+
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- uses: actions/checkout@v1
29+
- name: npm install and build webpack
30+
run: |
31+
npm install
32+
npm run build
33+
- uses: actions/upload-artifact@master
34+
with:
35+
name: webpack artifacts
36+
path: public/
37+
38+
deploy:
39+
name: Deploy Node.js app to AWS
40+
needs: build
41+
runs-on: ubuntu-latest
42+
43+
steps:
44+
- uses: actions/checkout@v1
45+
46+
- name: Download built artifact
47+
uses: actions/download-artifact@master
48+
with:
49+
name: webpack artifacts
50+
path: public
51+
52+
- name: Deploy to AWS
53+
uses: docker://admiralawkbar/aws-nodejs:latest
54+
env:
55+
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
56+
AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }}
57+
```

responses/04_merge.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# Completed Workflow
22

3-
Nice job, you've done it!
3+
Nice job, you've done it!
44

55
It won't be "working" yet, because our next step is to work on the configuration files that AWS will need. But, the logic for this workflow is complete.
66

77
## Step 4: Merge the staging workflow
88

9-
### :keyboard: Activity: Merge this staging workflow pull request
9+
### :keyboard: Activity: Merge this staging workflow pull request
10+
11+
1. Merge this pull request
12+
2. Delete the `staging-workflow` branch`

responses/05_confirm-aws.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1-
# AWS Configuration
1+
# AWS Configuration - S3 Buckets
22

3-
## Step 5: Confirm AWS configuration
3+
For deployment, we will be using AWS.
44

5-
### :keyboard: Activity: Create an AWS account by the following specifications, and confirm here.
5+
### S3 Buckets
6+
7+
Amazon S3 Buckets are containers. They're also a very flexible type of data storage- they can be configured to work in many different types of ways. They're popular for their security, scalability, and dependability. Our S3 Bucket will be the container that our application is deployed in, both in staging and in production.
8+
9+
## Step 5: Confirm AWS S3 configuration
10+
11+
### :keyboard: Activity: Create an AWS account by the following specifications, and confirm here
12+
13+
1. Create an account at [aws.amazon.com](https://aws.amazon.com/)
14+
- _This requires credit card information. If you'd like to continue with the course without an AWS account, Learning Lab will still respond, but none of the deployments will work._
15+
2. [Create an S3 bucket](https://docs.aws.amazon.com/AmazonS3/latest/gsg/CreatingABucket.html)
16+
- If you aren't sure how to get there, you can search for `S3`.
17+
- The region needs to be the same as what is specified in the `aws-config.yml` file in this pull request. :eyes: **For this exercise, choose us-west-2**. :eyes: If you'd like to choose another region, make sure to update the `aws-config.yml` file to match.
18+
- For all other options, accept the defaults.
19+
3. Confirm that you've created an S3 bucket by commenting anything in this pull request

responses/06_env-variables.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
11
# Environment Variables
22

3-
## Step 6: Enter environment variables
3+
### Access keys for IAM Users
44

5-
### :keyboard: Activity: Enter your AWS environment variables in this repository
5+
To automate the authentication, AWS recommends using a process called [IAM users](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html). By creating a specific key for a purpose or individual, specific scopes can be specified and access can be tracked.
66

7-
Then confirm you've done that by commenting.
7+
When you create an access key, the key pair is active by default, and you can use the pair right away. You will be adding the following two secrets to this repository:
8+
9+
- **AWS_ACCESS**: This serves as the user identifying token. "Access key ID"
10+
- **AWS_SECRET**: This represents the secret key value pair that's like a password. It's under "Secret access key".
11+
12+
## Step 6: Create and store environment variables
13+
14+
### :keyboard: Activity: Create your AWS IAM secrets and enter them in this repository
15+
16+
1. Add the tokens to this repository with the token name `AWS_SECRET_KEY`
17+
2. Once you are done, confirm here by commenting anything in this pull request
18+
3. Sign in to the AWS Management Console and open the IAM console at https://console.aws.amazon.com/iam/
19+
4. In the navigation pane, choose **Users**
20+
5. Create a new user with **programmatic access**
21+
6. When setting permissions, search for and select **AmazonS3FullAccess**
22+
7. Use a tag that will identify this token pair, like **Deployment Learning Lab**
23+
8. **Download .csv file** to save the access key ID and secret access key to a CSV file on your computer
24+
- Store the file in a secure location
25+
- ⚠️ _You will not have access to the secret access key again after this dialog box closes_
26+
- After you download the CSV file, choose **Close**
27+
9. Save the _Access key ID_ as a secret, named `AWS_ACCESS_KEY` in the **Settings > Secrets**
28+
10. Save the _Secret access key_ as a secret, named `AWS_SECRET_KEY` in the **Settings > Secrets**
29+
11. Once you are done, confirm here by commenting anything in this pull request

0 commit comments

Comments
 (0)