Skip to content

Commit 83eb2aa

Browse files
committed
Update workflows to build and publish images
1 parent 89e6e62 commit 83eb2aa

File tree

5 files changed

+232
-15
lines changed

5 files changed

+232
-15
lines changed
+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Docker build and push
2+
description: Build the image and pushes to registry
3+
4+
inputs:
5+
version:
6+
description: The version to use for the Docker image
7+
required: true
8+
dockerfile_path:
9+
description: Dockerfile location
10+
required: true
11+
image_name:
12+
description: The Docker image name, with the registry prefix
13+
required: true
14+
registry_dev:
15+
description: Docker registry dev
16+
required: true
17+
registry_prod:
18+
description: Docker registry prod
19+
required: true
20+
registry_username:
21+
description: Docker registry username
22+
required: true
23+
registry_password:
24+
description: Docker registry password
25+
required: true
26+
build_args:
27+
description: Arguments to pass to docker build
28+
required: false
29+
default: ''
30+
31+
32+
runs:
33+
using: composite
34+
steps:
35+
- name: Setup up Docker Buildx
36+
uses: docker/setup-buildx-action@v3
37+
38+
- name: Generate Date Version
39+
id: date-version
40+
uses: StackEng/CoreEngineering.CITools/actions/date_version@v1
41+
42+
- name: Docker Image Metadata
43+
id: metadata
44+
uses: docker/metadata-action@v5
45+
with:
46+
images: ${{ inputs.image_name }}
47+
# https://github.com/docker/metadata-action/tree/master?tab=readme-ov-file#priority-attribute
48+
# The default priority of sha is 100, and for custom/raw tags is 200. The highest the most priority.
49+
# We want the sha tag to be the one used for the OCI label and the version output, so we set the priority of the custom date tag to the lowest.
50+
tags: |
51+
type=sha,priority=100
52+
${{ inputs.version }},priority=1
53+
${{ github.ref_name == 'main' && '' || format('pr-{0}', github.event.pull_request.number) }}
54+
flavor: latest=false
55+
56+
- name: Login to Docker Registry - dev
57+
uses: docker/login-action@v3
58+
with:
59+
registry: ${{ inputs.registry_dev }}
60+
username: ${{ inputs.registry_username }}
61+
password: ${{ inputs.registry_password }}
62+
63+
- name: Login to Docker Registry - prod
64+
uses: docker/login-action@v3
65+
with:
66+
registry: ${{ inputs.registry_prod }}
67+
username: ${{ inputs.registry_username }}
68+
password: ${{ inputs.registry_password }}
69+
70+
- name: Build Image
71+
uses: docker/build-push-action@v5
72+
with:
73+
push: true
74+
context: .
75+
file: ${{ inputs.dockerfile_path }}
76+
tags: ${{ steps.metadata.outputs.tags }}
77+
labels: ${{ steps.metadata.outputs.labels }}
78+
provenance: true
79+
build-args: |
80+
DOTNET_VERSION=${{ env.DOTNET_VERSION }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Build docker
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
version:
7+
type: string
8+
required: true
9+
secrets:
10+
registry_username:
11+
required: true
12+
registry_password:
13+
required: true
14+
nuget_user:
15+
required: true
16+
nuget_password:
17+
required: true
18+
19+
env:
20+
BUILDKIT_PROGRESS: plain
21+
SERVICE_IMAGE_NAME: ${{ github.ref_name == 'main' && vars.CLOUDSMITH_DOCKER_REGISTRY_PROD || vars.CLOUDSMITH_DOCKER_REGISTRY_DEV }}/stackeng/opserver/opserver
22+
23+
jobs:
24+
build_docker:
25+
name: Docker build and push
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout Repository
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0 #Fetch entire history for NerdBank to calculate the version
32+
33+
- name: Setup NuGet access
34+
uses: StackEng/PlatEngTools/actions/nuget-sources@main
35+
with:
36+
GH_NUGET_FEED: ${{ vars.CLOUDSMITH_NUGET }}
37+
GH_NUGET_USER: ${{ secrets.nuget_user }}
38+
GH_NUGET_RO_PAT: ${{ secrets.nuget_password }}
39+
NUGET_CLEANUP_FEEDS: ProGet
40+
41+
- uses: ./.github/actions/build_docker
42+
id: image
43+
with:
44+
version: ${{ inputs.version }}
45+
dockerfile_path: ./Dockerfile
46+
image_name: ${{ env.SERVICE_IMAGE_NAME }}
47+
registry_dev: ${{ vars.CLOUDSMITH_DOCKER_REGISTRY_DEV }}
48+
registry_prod: ${{ vars.CLOUDSMITH_DOCKER_REGISTRY_PROD }}
49+
registry_username: ${{ secrets.registry_username }}
50+
registry_password: ${{ secrets.registry_password }}
51+
scan_image: true
52+
53+
- name: Await opserver docker image to be ready in Cloudsmith
54+
uses: StackEng/TeamsScaleTools/actions/cloudsmith-awaiter@main
55+
with:
56+
cloudsmith_api_key: ${{ secrets.registry_password }}
57+
cloudsmith_org: stackoverflow
58+
cloudsmith_repo: ${{ github.ref_name == 'main' && 'cr' || 'cr-dev' }}
59+
cloudsmith_query: "name:opserver tag:${{ inputs.version }}"
60+

.github/workflows/build_cnab.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Build CNAB invocation image
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
version:
7+
description: The version to use for the Octopus release
8+
type: string
9+
required: true
10+
secrets:
11+
registry_username:
12+
required: true
13+
registry_password:
14+
required: true
15+
16+
env:
17+
CNAB_IMAGE_NAME: ${{ github.ref_name == 'main' && vars.CLOUDSMITH_DOCKER_REGISTRY_PROD || vars.CLOUDSMITH_DOCKER_REGISTRY_DEV }}/stackeng/opserver/opserver-cnab
18+
19+
jobs:
20+
build_image:
21+
name: Build and release CNAB invocation image
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout Repository
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
28+
29+
- uses: ./.github/actions/build_docker
30+
with:
31+
version: ${{ inputs.version }}
32+
dockerfile_path: ./cnab/build/Dockerfile
33+
image_name: ${{ env.CNAB_IMAGE_NAME }}
34+
registry_dev: ${{ vars.CLOUDSMITH_DOCKER_REGISTRY_DEV }}
35+
registry_prod: ${{ vars.CLOUDSMITH_DOCKER_REGISTRY_PROD }}
36+
registry_username: ${{ secrets.registry_username }}
37+
registry_password: ${{ secrets.registry_password }}
38+

.github/workflows/docker.yml

-15
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Build images and create Octopus release
2+
run-name: 'Build images and create release'
3+
4+
on:
5+
workflow_dispatch:
6+
pull_request:
7+
paths-ignore:
8+
- README.md
9+
push:
10+
branches:
11+
- main
12+
paths-ignore:
13+
- README.md
14+
15+
jobs:
16+
generate_date_version:
17+
runs-on: ubuntu-latest
18+
outputs:
19+
version: ${{ steps.date-version.outputs.version }}
20+
steps:
21+
- name: Generate Date Version
22+
id: date-version
23+
uses: StackEng/CoreEngineering.CITools/actions/date_version@v1
24+
25+
build_docker:
26+
needs: [generate_date_version]
27+
uses: ./.github/workflows/build_app_docker_image.yml
28+
with:
29+
version: ${{ needs.generate_date_version.outputs.version }}
30+
secrets:
31+
registry_username: ${{ secrets.CLOUDSMITH_API_ACCOUNT }}
32+
registry_password: ${{ secrets.CLOUDSMITH_API_KEY }}
33+
nuget_user: ${{ secrets.CLOUDSMITH_API_ACCOUNT }}
34+
nuget_password: ${{ secrets.CLOUDSMITH_API_KEY }}
35+
36+
build_migrations:
37+
needs: [generate_date_version]
38+
uses: ./.github/workflows/build_migrations_image.yml
39+
with:
40+
version: ${{ needs.generate_date_version.outputs.version }}
41+
secrets:
42+
registry_username: ${{ secrets.CLOUDSMITH_API_ACCOUNT }}
43+
registry_password: ${{ secrets.CLOUDSMITH_API_KEY }}
44+
nuget_user: ${{ secrets.CLOUDSMITH_API_ACCOUNT }}
45+
nuget_password: ${{ secrets.CLOUDSMITH_API_KEY }}
46+
47+
build_cnab:
48+
uses: ./.github/workflows/build_cnab.yml
49+
needs: [generate_date_version]
50+
with:
51+
version: ${{ needs.generate_date_version.outputs.version }}
52+
secrets:
53+
registry_username: ${{ secrets.CLOUDSMITH_API_ACCOUNT }}
54+
registry_password: ${{ secrets.CLOUDSMITH_API_KEY }}

0 commit comments

Comments
 (0)