Skip to content

Commit

Permalink
Merge pull request #12 from githubschool/Deploy
Browse files Browse the repository at this point in the history
Create deploy-prod-gcr.yml
  • Loading branch information
jdesulme authored Oct 13, 2021
2 parents c24ecde + fe47535 commit 1bdeb5b
Showing 1 changed file with 128 additions and 0 deletions.
128 changes: 128 additions & 0 deletions .github/workflows/deploy-prod-gcr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# This is a basic workflow to help you get started with Actions

name: Docker Production

# Controls when the action will run.
on:
push:
branches:
- 'master'
- 'main'

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
docker-prod-release:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# You could use the following lines to help make sure only X people start the workflow
# if: github.actor == 'admiralawkbar' || github.actor == 'jwiebalk'

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout source code
uses: actions/checkout@v2

#########################
# Install Docker BuildX #
#########################
- name: Install Docker BuildX
uses: docker/setup-buildx-action@v1

######################################
# Login to GitHub Container Registry #
######################################
- name: Login to GitHub Container registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ secrets.GCR_USERNAME }}
password: ${{ secrets.GCR_TOKEN }}

# Update deployment API
- name: start deployment
uses: bobheadxi/[email protected]
id: deployment
with:
step: start
token: ${{ secrets.GITHUB_TOKEN }}
env: Production

# Create a GitHub Issue with the info from this build
- name: Create GitHub Issue
uses: actions/[email protected]
id: create-issue
with:
# https://octokit.github.io/rest.js/v18#issues-create
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const create = await github.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: "Deploying to production",
body: 'Currently deploying...'
})
console.log('create', create)
return create.data.number
########################################
# Convert repository name to lowercase #
########################################
- name: Repository Name to lowercase
run: |
echo IMAGE_REPOSITORY="$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV"
###########################################
# Build and Push containers to registries #
###########################################
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: |
ghcr.io/${{ env.IMAGE_REPOSITORY }}:latest
ghcr.io/${{ env.IMAGE_REPOSITORY }}:v1
# Update Deployment API
- name: update deployment status
uses: bobheadxi/[email protected]
if: always()
with:
step: finish
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
deployment_id: ${{ steps.deployment.outputs.deployment_id }}
env_url: https://github.com/orgs/githubschool/packages?repo_name=github-actions-training-jdesulme

- name: Update issue success
uses: actions/[email protected]
if: success()
with:
# https://octokit.github.io/rest.js/v18#issues-create
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: "${{ steps.create-issue.outputs.result }}",
title: "New issue created",
body: "Successfully deployed production"
})
- name: Update issue failure
uses: actions/[email protected]
if: failure()
with:
# https://octokit.github.io/rest.js/v18#issues-create
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: "${{ steps.create-issue.outputs.result }}",
title: "New issue created",
body: "Failed to deploy to production"
})

0 comments on commit 1bdeb5b

Please sign in to comment.