-
Notifications
You must be signed in to change notification settings - Fork 2
144 lines (142 loc) · 5.58 KB
/
Copy pathworkflow-docker.yaml
File metadata and controls
144 lines (142 loc) · 5.58 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
name: Docker Workflow
# Standard workflow for any projects only building and running docker images. For language specific projects, see other
# workflows within the shared library.
on:
workflow_call:
inputs:
dockerfile_location:
type: string
default: "Dockerfile"
description: "The location of the Dockerfile relative to the root of the repository."
repo_url:
type: string
default: "harbor.devops.k8s.rcsb.org"
description: "The URL of the remote Docker image repository."
repo_project:
type: string
required: true
description: "The name of the project or organization in the remote Docker image repository."
docker_image_name:
type: string
required: true
description: "The name of the Docker image to create."
docker_build_context:
type: string
default: "."
description: "The path location of the docker build context, relative to the project root."
mainline_branch:
type: string
default: master
description: "The mainline branch for the repo. Deployments to the staging and production environments are done only on push to this branch. Defaults to master."
do_staging_build:
type: string
default: "false"
description: "Build, tag, and push a docker image with the staging tag."
do_production_build:
type: string
default: "true"
description: "Build, tag, and push a docker image with the production tag."
workflow_dispatch:
inputs:
dockerfile_location:
type: string
default: "Dockerfile"
description: "The location of the Dockerfile relative to the root of the repository."
repo_url:
type: string
default: "harbor.devops.k8s.rcsb.org"
description: "The URL of the remote Docker image repository."
repo_project:
type: string
required: true
description: "The name of the project or organization in the remote Docker image repository."
docker_image_name:
type: string
required: true
description: "The name of the Docker image to create."
docker_build_context:
type: string
default: "."
description: "The path location of the docker build context, relative to the project root."
mainline_branch:
type: string
default: github.event.repository.default_branch
description: "The mainline branch for the repo. Deployments to the staging and production environments are done only on push to this branch. Defaults to the repo's default branch."
do_staging_build:
type: string
default: "false"
description: "Build, tag, and push a docker image with the staging tag."
do_production_build:
type: string
default: "true"
description: "Build, tag, and push a docker image with the production tag."
jobs:
debug:
name: "Debug conditionals"
runs-on:
- "self-hosted"
- "dind"
- "east"
steps:
- name: "Output inputs and refs"
run: |
echo "=== Check branch conditionals"
echo "github.ref_name: ${{ github.ref_name }}"
echo "inputs.mainline_branch: ${{ inputs.mainline_branch }}"
echo "Is github.ref_name == inputs.mainline_branch: ${{ github.ref_name == inputs.mainline_branch }}"
echo "=== Check event conditionals"
echo "github.event_name: ${{ github.event_name }}"
echo "Is github.event_name != 'pull_request': ${{ github.event_name != 'pull_request' }}"
echo "=== Check environment conditionals"
echo "inputs.do_production_build: ${{ inputs.do_production_build }}"
echo "inputs.do_staging_build: ${{ inputs.do_staging_build }}"
lint:
name: "Lint Dockerfile"
uses: ./.github/workflows/lint_docker.yaml
with:
dockerfile_location: ${{ inputs.dockerfile_location }}
build-and-push:
name: "Build and Push Docker Image"
uses: ./.github/workflows/build_docker.yaml
needs: lint
with:
repo_url: ${{ inputs.repo_url }}
repo_project: ${{ inputs.repo_project }}
docker_image_name: ${{ inputs.docker_image_name }}
docker_build_context: ${{ inputs.docker_build_context }}
# Without this the build ignored dockerfile_location and always read
# <context>/Dockerfile, so a repo whose Dockerfile is named anything else linted
# the right file and then failed to build.
dockerfile_location: ${{ inputs.dockerfile_location }}
# Staging jobs
build_docker_staging:
name: "Push docker image with staging tag"
if: |
inputs.do_staging_build == 'true' &&
github.ref_name == inputs.mainline_branch &&
github.event_name != 'pull_request'
needs:
- build-and-push
uses: ./.github/workflows/retag_docker.yaml
with:
repo_url: "${{ inputs.repo_url }}"
repo_project: "${{ inputs.repo_project }}"
docker_image_name: "${{ inputs.docker_image_name }}"
old_tag: "${{ github.ref_name }}"
new_tag: "staging"
# Production jobs
build_docker_production:
name: "Push docker image with production tag"
if: |
inputs.do_production_build == 'true' &&
github.ref_name == inputs.mainline_branch &&
github.event_name != 'pull_request'
needs:
- build-and-push
uses: ./.github/workflows/retag_docker.yaml
with:
repo_url: "${{ inputs.repo_url }}"
repo_project: "${{ inputs.repo_project }}"
docker_image_name: "${{ inputs.docker_image_name }}"
old_tag: "${{ github.ref_name }}"
new_tag: "production"