-
Notifications
You must be signed in to change notification settings - Fork 0
Production deployment workflow #4
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
Conversation
…lows/deploy-prod.yml
|
Great! The syntax you used tells GitHub Actions to only run that workflow when a commit is made to the master branch. Deploying to productionJust 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 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
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: docker://admiralawkbar/aws-nodejs:latest
env:
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }} |
Workflow stepsWe'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.
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
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: docker://admiralawkbar/aws-nodejs:latest
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: tic-tac-toe |
Completed WorkflowNice job, you've done it! Step 11: Merge the production workflow⌨️ Activity: Merge this pull request and test the production deployment workflow
|
Different triggers
Deployments to production can be manual (like through a Chat Ops command), or automated (if, say, we trust our pull request review process and we've followed continuous integration practices).
We'll trigger a deployment to the production environment whenever something is committed to master. Our master branch is protected, so the only way for commits to appear on master is for a pull request to have been created and gone through the proper review process and merged.
Step 8: Write the production deployment trigger
Let's create a new workflow that deals specifically with commits to master and handles deployments to prod.
⌨️ Activity: Write the production deployment trigger on merge to master
deploy-prod.ymlfile on this branch, or use this quick link (We recommend opening the quick link in another tab).github/workflows/deploy-prod.ymlpushtriggerbranchesinside the push block- masterinside the branches blockThe file should look like this when you're finished: