-
Notifications
You must be signed in to change notification settings - Fork 1
128 lines (115 loc) · 4.44 KB
/
deploy-prod-gcr.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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"
})