-
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 main branch. Deploying to productionJust like with the other workflow, we'll need to build our application and deploy to Azure 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⌨️ Activity: Add jobs to a production deployment 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, and that we won't be filtering by labels. name: Production deployment
on:
push:
branches:
- main
env:
DOCKER_IMAGE_NAME: piraces-azure-ttt # Must not exist as a package associated with a different repo!
IMAGE_REGISTRY_URL: docker.pkg.github.com
#################################################
### USER PROVIDED VALUES ARE REQUIRED BELOW ###
#################################################
#################################################
### REPLACE USERNAME WITH GH USERNAME ###
AZURE_WEBAPP_NAME: piraces-ttt-app
#################################################
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@main
with:
name: webpack artifacts
path: public/
Build-Docker-Image:
runs-on: ubuntu-latest
needs: build
name: Build image and store in GitHub Packages
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Download built artifact
uses: actions/download-artifact@main
with:
name: webpack artifacts
path: public
- name: create image and store in Packages
uses: mattdavis0351/actions/docker-gpr@1.3.0
with:
repo-token: ${{secrets.GITHUB_TOKEN}}
image-name: ${{env.DOCKER_IMAGE_NAME}}
Deploy-to-Azure:
runs-on: ubuntu-latest
needs: Build-Docker-Image
name: Deploy app container to Azure
steps:
- name: "Login via Azure CLI"
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- uses: azure/docker-login@v1
with:
login-server: ${{env.IMAGE_REGISTRY_URL}}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy web app container
uses: azure/webapps-deploy@v2
with:
app-name: ${{env.AZURE_WEBAPP_NAME}}
images: ${{env.IMAGE_REGISTRY_URL}}/${{ github.repository }}/${{env.DOCKER_IMAGE_NAME}}:${{ github.sha }}
- name: Azure logout
run: |
az logoutI'll respond when you push a commit on this branch. |
Completed WorkflowNice job, you've done it! Step 11: Merge the production workflow⌨️ Activity: Merge this pull request and test the production deployment workflow
I'll respond when you merge this pull request. |
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. The cloud environmentThroughout the course you've spun up resources that, if left unattended, could incur billing or consume your free minutes from the cloud provider. Let's tear down those environments so that you can keep your minutes for more learning! Step 12: Clean up your environment⌨️ Activity: Destroy any running resources so you don't incur charges
I'll respond when you apply a label to this pull request. |
|
Now that you've applied the proper label, let's wait for the GitHub Actions workflow to complete. When it's finished, you can confirm that your environment has been destroyed by visiting your app's URL, or by logging into the Azure portal to see it is not running. This course is now complete! I'll stop responding but the fun doesn't have to stop here. Now...what will you learn next? |

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 main. Our main branch is protected, so the only way for commits to appear on main 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 main and handles deployments to prod.
⌨️ Activity: Write the production deployment trigger on merge to main
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- maininside the branches blockThe file should look like this when you're finished:
I'll respond when you push a commit on this branch.