Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test the staging action #3

Merged
merged 4 commits into from
Jul 25, 2020
Merged

Test the staging action #3

merged 4 commits into from
Jul 25, 2020

Conversation

github-learning-lab[bot]
Copy link
Contributor

Testing the workflow

Now that the proper configuration and workflow files are present, let's test this action out!

Step 7: Test the staging action

In this pull request, there's a small change to the game. Once you add the label, you should be able to see the deployment!

⌨️ Activity: Add the proper label to this pull request

  1. On the right hand side, click Labels or the gear next to it
  2. Select the label titled stage

@github-learning-lab github-learning-lab bot mentioned this pull request Jul 25, 2020
@github-learning-lab
Copy link
Contributor Author

Great! The syntax you used tells GitHub Actions to only run that workflow when a commit is made to the master branch.

Deploying to production

Just like with the other workflow, we'll need to build our application and deploy to AWS using the same action as before because we are working with the same Node.js app.

Continuous delivery is a concept that contains many behaviors and other, more specific concepts. One of those concepts is test in production. That can mean different things to different projects and different companies, and isn't a strict rule that says you are or aren't "doing CD".

In our case, we can match our production environment to be exactly like our staging environment. This minimizes opportunities for surprises once we deploy to production.

Step 9: Complete the deployment to production workflow

⌨️ Commit the steps to the production workflow that allow you to deploy on merge to master

  1. Edit the deploy-prod.yml file on this branch, or use this quick link (We recommend opening the quick link in another tab)
  2. Add a build and deploy job to the workflow

It should look like the file below when you are finished. Note that not much has changed from our staging workflow, except for our trigger.

name: Production deployment

on: 
  push:
    branches:
      - master

jobs:
  build:
    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:  github/deploy-nodejs@master
        env:
          AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
          AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }}

@wpride wpride added the stage label Jul 25, 2020
@wpride
Copy link
Owner

wpride commented Jul 25, 2020

@brianamarie At this point in the course, deploy-prod.yml does not exist and the provided link is dead

@github-learning-lab
Copy link
Contributor Author

Workflow steps

We'll add a final section to our production workflow that packages up our application in a Docker container and publishes it to GitHub Packages. This step is important for the traceability of your deployed artifacts.

We'll only use one new action here created by a GitHubber, which allows us to push a container to GitHub Packages.

  • mattdavis0351/actions/docker-gpr

All of this happens automatically once a pull request is merged!

Step 10: Create the Docker image and push it to GitHub Packages

⌨️ Activity: Write the steps for the production deployment workflow

  1. Edit the deploy-prod.yml file on this branch, or use this quick link (We recommend opening the quick link in another tab)
  2. Add a job to your workflow as follows:
    Build-and-Push-Docker-Image:
    runs-on: ubuntu-latest
    needs: build
    name: Docker Build, Tag, Push
    steps:
      - name: Checkout
        uses: actions/checkout@v1
    
      - name: Download built artifact
        uses: actions/download-artifact@master
        with:
          name: webpack artifacts
          path: public
    
      - name: Build, Tag, Push
        uses: mattdavis0351/actions/docker-gpr@v1
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          image-name: wpride-aws-ttt
  3. Commit the workflow to this branch.

The complete workflow file should look like this:

name: Production deployment

on: 
  push:
    branches:
      - master

jobs:
  build:
    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:  github/deploy-nodejs@master
        env:
          AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
          AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }}

  Build-and-Push-Docker-Image:
    runs-on: ubuntu-latest
    needs: build
    name: Docker Build, Tag, Push
    steps:
      - name: Checkout
        uses: actions/checkout@v1

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

      - name: Build, Tag, Push
        uses: mattdavis0351/actions/docker-gpr@v1
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          image-name: wpride-aws-ttt

@github-learning-lab
Copy link
Contributor Author

Completed Workflow

Nice job, you've done it!

Step 11: Merge the production workflow

⌨️ Activity: Merge this pull request and test the production deployment workflow

  1. Merge this pull request
  2. Delete the branch

@wpride wpride merged commit 8037120 into master Jul 25, 2020
@github-learning-lab
Copy link
Contributor Author

Nice work!

Now, we just have to wait for the deployment to occur, and for the package to be published to GitHub Packages. When it's completed, you should be able to see it in the Packages section of your repository. You can get the deployment URL in the Actions log, just like the staging URL.

celebrate

This course is now complete! I'll stop responding but the fun doesn't have to stop here.

Now...what will you learn next?

@wpride wpride deleted the staging-test branch July 25, 2020 17:56
@wpride
Copy link
Owner

wpride commented Jul 25, 2020

@brianamarie Other than that, flawless and incredibly helpful course! Thank you.

@brianamarie
Copy link
Contributor

brianamarie commented Jul 27, 2020

Thanks! I will open an issue in the course repo so we can look into this. githubtraining/continuous-delivery-aws#30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants