Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3ade34d
small change
brianamarie Oct 31, 2019
23b2ff1
improve first instruction 01
brianamarie Nov 1, 2019
278052b
give the solution for step 2
brianamarie Nov 1, 2019
5eba909
improve context for 02
brianamarie Nov 1, 2019
da96c6a
add template of correct answer for 3
brianamarie Nov 1, 2019
7c5c32a
we cant approve, we remove protections
brianamarie Nov 1, 2019
02d48fa
add base instructions for step 5 aws token confirmation
brianamarie Nov 1, 2019
e6a224e
readd branch protections
brianamarie Nov 1, 2019
73b2026
put proper aws instructions into steps 5 and 6
brianamarie Nov 1, 2019
89aaf9b
formally request the learner review
brianamarie Nov 1, 2019
7505bfc
add step so label already exists
brianamarie Nov 1, 2019
85150e9
talk to the same subject of the sentence
brianamarie Nov 1, 2019
5429bc0
put answers into steps for prod workflow
brianamarie Nov 1, 2019
3a8a730
in step 9 tell user to change directory name
brianamarie Nov 1, 2019
f90b1a8
we cant approve our own prs
brianamarie Nov 1, 2019
546b20b
add information about aws
brianamarie Nov 1, 2019
4318fba
break up the aws steps differently
brianamarie Nov 1, 2019
91dc5fc
better 05 instructions
brianamarie Nov 1, 2019
1ccd109
formatting for 06
brianamarie Nov 1, 2019
4a69089
improve context for steps 2 3 and 4
brianamarie Nov 1, 2019
dacb03b
more info on approve
brianamarie Nov 1, 2019
919df46
add instructions for staging
brianamarie Nov 1, 2019
0c9c11a
deployment prod description;
brianamarie Nov 1, 2019
7fe74e2
better workflow 2 steps info
brianamarie Nov 1, 2019
d8a1cec
better name for final step
brianamarie Nov 1, 2019
9593fda
correct links so they are pull not pulls
brianamarie Nov 1, 2019
b60f1db
better instructions around s3 stuff
brianamarie Nov 1, 2019
4d1c8eb
instruction formatting
brianamarie Nov 1, 2019
22f1f6c
tell it which permissions
brianamarie Nov 1, 2019
b256f7d
access and secret key name instruction update
brianamarie Nov 1, 2019
dffa197
add course details
brianamarie Nov 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 38 additions & 24 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ before:
# production-deployment-workflow: with the workflow file stub for production deploy from merge
# staging-test: with a small change to the app that can be seen in staging

# we create a staging label that will be used later to test

- type: createLabel
name: stage
color: f87000

# PART 1: STAGING WORKFLOW

# Step 1: Configure a trigger based on labels
Expand All @@ -39,7 +45,7 @@ steps:
- title: Configure a trigger based on labels
description: Configure the workflow trigger based on an a label being added
event: pull_request
link: '{{ repoUrl }}/pulls/1'
link: '{{ repoUrl }}/pull/1'
actions:
# We validate that trigger is correct
#- type: gate
Expand All @@ -54,7 +60,7 @@ steps:
- title: Choose the environment for AWS
description: Choose the Ubuntu environment for our app
event: pull_request
link: '{{ repoUrl }}/pulls/1'
link: '{{ repoUrl }}/pull/1'
actions:

# We validate
Expand All @@ -69,24 +75,25 @@ steps:
- title: Write the steps for the staging workflow
description: Write the steps for the staging deployment workflow
event: pull_request
link: '{{ repoUrl }}/pulls/1'
link: '{{ repoUrl }}/pull/1'
actions:

# We validate
#- type: gate

# We approve
- type: createReview
event: APPROVE
# We remove branch protections
- type: removeBranchProtection

# Step 4: Merge the staging workflow
# We tell the user to merge
body: 04_merge.md
- type: respond
with: 04_merge.md

# event: merge
- title: Merge the staging workflow
description: Merge this staging workflow pull request
event: pull_request.closed
link: '{{ repoUrl }}/pulls/1'
link: '{{ repoUrl }}/pull/1'
actions:

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

# we reprotect master for the next PR
- type: updateBranchProtection

# PART 2: AWS CONFIGURATION

Expand All @@ -118,10 +127,10 @@ steps:

# event: responding with a comment

- title: Confirm AWS configuration
- title: Confirm AWS S3 configuration
description: Create an AWS account by the following specifications, and confirm here
event: issue_comment.created
link: '{{ repoUrl }}/pulls/2'
link: '{{ repoUrl }}/pull/2'
actions:

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

# event: Respond with a comment
- title: Enter environment variables
description: Enter your AWS environment variables into this repository, and confirm here
- title: Create and store environment variables
description: Create your AWS IAM secrets and enter them in this repository
event: issue_comment.created
link: '{{ repoUrl }}/pulls/2'
link: '{{ repoUrl }}/pull/2'
actions:

# Validate if possible
Expand All @@ -147,12 +156,16 @@ steps:
- type: respond
with: 07_approve.md

# we formally request their approval
- type: requestReviewFromRegistrant
pullRequest: Configure AWS

# event: approval

- title: Approve pull request
description: Approve pull request adding the aws-config.yml and sam-template.yml
event: pull_request_review
link: '{{ repoUrl }}/pulls/2'
link: '{{ repoUrl }}/pull/2'
actions:

# we make sure it's approved
Expand Down Expand Up @@ -191,7 +204,7 @@ steps:
- title: Test the staging action
description: Test the new action to deploy labeled pull requests to staging
event: pull_request.labeled
link: '{{ repoUrl }}/pulls/3'
link: '{{ repoUrl }}/pull/3'
actions:

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

# We validate
Expand All @@ -233,7 +246,7 @@ steps:
- title: Choose the environment for AWS
description: Commit the proper environment for AWS to the workflow file
event: pull_request
link: '{{ repoUrl }}/pulls/3'
link: '{{ repoUrl }}/pull/3'
actions:

# We validate
Expand All @@ -250,7 +263,7 @@ steps:
- title: Write the steps for the production workflow
description: Write the steps for the production deployment to the workflow file
event: pull_request
link: '{{ repoUrl }}/pulls/3'
link: '{{ repoUrl }}/pull/3'
actions:

# We validate
Expand All @@ -261,18 +274,19 @@ steps:

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

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

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

# event: merge

- title: Merge this pull request
- title: Merge the production workflow
description: Merge this pull request and test the production deployment workflow
event: pull_request.closed
link: '{{ repoUrl }}/pulls/3'
link: '{{ repoUrl }}/pull/3'
actions:

# check that its merged
Expand Down
9 changes: 9 additions & 0 deletions course-details.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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.

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:

- Create two workflow files
- Configure AWS S3 for deployment
- Use secrets to store tokens
- Deploy to staging and production
- Practice using GitHub Actions
31 changes: 28 additions & 3 deletions responses/01_label-trigger.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,38 @@ We will be working with Continuous Delivery. We will...
- Use AWS configuration

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

### What is Continuous Delivery?

I'll tell ya!
According to [continuousdelivery.com](https://continuousdelivery.com/),

> 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.

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.

## Step 1: Configure a trigger based on labels

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.

### :keyboard: Activity: Configure the workflow trigger based on an a label being added

1. Edit this file
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`
3. Edit the contents of this file to trigger on a label

Your result should look like this:

```yml
name: Staging deployment

on:
pull_request:
types: [labeled]

jobs:
build:
if: contains(github.event.pull_request.labels.*.name, 'stage')

```
24 changes: 22 additions & 2 deletions responses/02_environment.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
# Choosing deployment environments

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.
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.

### What are the options?

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.

## Step 2: Choose the environment for AWS

### :keyboard: Activity: Choose the Ubuntu environment for our app
For our `Node.js` application, we will be using a basic Ubuntu environment.

### :keyboard: Activity: Choose the Ubuntu environment for our app

```yml
name: Staging deployment

on:
pull_request:
types: [labeled]

jobs:
build:
if: contains(github.event.pull_request.labels.*.name, 'stage')

runs-on: ubuntu-latest
```
52 changes: 51 additions & 1 deletion responses/03_workflow-steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,54 @@ So far, the workflow knows what the trigger is and what environment to run in. B

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

### :keyboard: Activity: Write the steps for the staging deployment workflow
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:

- `actions/checkout`
- `Deploy to AWS`

### :keyboard: Activity: Write the steps for the staging deployment workflow

```yml
name: Staging deployment

on:
pull_request:
types: [labeled]

jobs:
build:
if: contains(github.event.pull_request.labels.*.name, 'stage')

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: npm install and build webpack
run: |
npm install
npm run build
- uses: actions/upload-artifact@master
with:
name: webpack artifacts
path: public/

deploy:
name: Deploy Node.js app to AWS
needs: build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: Download built artifact
uses: actions/download-artifact@master
with:
name: webpack artifacts
path: public

- name: Deploy to AWS
uses: docker://admiralawkbar/aws-nodejs:latest
env:
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }}
```
7 changes: 5 additions & 2 deletions responses/04_merge.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Completed Workflow

Nice job, you've done it!
Nice job, you've done it!

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.

## Step 4: Merge the staging workflow

### :keyboard: Activity: Merge this staging workflow pull request
### :keyboard: Activity: Merge this staging workflow pull request

1. Merge this pull request
2. Delete the `staging-workflow` branch`
20 changes: 17 additions & 3 deletions responses/05_confirm-aws.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# AWS Configuration
# AWS Configuration - S3 Buckets

## Step 5: Confirm AWS configuration
For deployment, we will be using AWS.

### :keyboard: Activity: Create an AWS account by the following specifications, and confirm here.
### S3 Buckets

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.

## Step 5: Confirm AWS S3 configuration

### :keyboard: Activity: Create an AWS account by the following specifications, and confirm here

1. Create an account at [aws.amazon.com](https://aws.amazon.com/)
- _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._
2. [Create an S3 bucket](https://docs.aws.amazon.com/AmazonS3/latest/gsg/CreatingABucket.html)
- If you aren't sure how to get there, you can search for `S3`.
- 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.
- For all other options, accept the defaults.
3. Confirm that you've created an S3 bucket by commenting anything in this pull request
28 changes: 25 additions & 3 deletions responses/06_env-variables.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
# Environment Variables

## Step 6: Enter environment variables
### Access keys for IAM Users

### :keyboard: Activity: Enter your AWS environment variables in this repository
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.

Then confirm you've done that by commenting.
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:

- **AWS_ACCESS**: This serves as the user identifying token. "Access key ID"
- **AWS_SECRET**: This represents the secret key value pair that's like a password. It's under "Secret access key".

## Step 6: Create and store environment variables

### :keyboard: Activity: Create your AWS IAM secrets and enter them in this repository

1. Add the tokens to this repository with the token name `AWS_SECRET_KEY`
2. Once you are done, confirm here by commenting anything in this pull request
3. Sign in to the AWS Management Console and open the IAM console at https://console.aws.amazon.com/iam/
4. In the navigation pane, choose **Users**
5. Create a new user with **programmatic access**
6. When setting permissions, search for and select **AmazonS3FullAccess**
7. Use a tag that will identify this token pair, like **Deployment Learning Lab**
8. **Download .csv file** to save the access key ID and secret access key to a CSV file on your computer
- Store the file in a secure location
- ⚠️ _You will not have access to the secret access key again after this dialog box closes_
- After you download the CSV file, choose **Close**
9. Save the _Access key ID_ as a secret, named `AWS_ACCESS_KEY` in the **Settings > Secrets**
10. Save the _Secret access key_ as a secret, named `AWS_SECRET_KEY` in the **Settings > Secrets**
11. Once you are done, confirm here by commenting anything in this pull request
Loading