-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCI-Docker-Image-Build-Template.yml
More file actions
74 lines (65 loc) · 2.34 KB
/
Copy pathCI-Docker-Image-Build-Template.yml
File metadata and controls
74 lines (65 loc) · 2.34 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
name: Build and Publish Docker Image
on:
workflow_call:
inputs:
DOCKER_ORGANIZATION_NAME:
required: true
type: string
DOCKER_IMAGENAME:
required: true
type: string
PUSH_IMAGE:
required: true
type: boolean
PLATFORMS:
required: false
type: string
default: "linux/amd64"
secrets:
docker_username:
required: true
docker_password:
required: true
jobs:
# define job to build and publish docker image
build-and-push-docker-image:
name: Build Docker image and push to repositories
environment: Docker
# run only when code is compiling and tests are passing
runs-on: ubuntu-latest
# steps to perform in job
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
# setup Docker buld action
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.docker_username }}
password: ${{ secrets.docker_password }}
- uses: Klemensas/action-autotag@stable
id: tag_step
with:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
package_root: docker/${{ inputs.DOCKER_ORGANIZATION_NAME }}/${{ inputs.DOCKER_IMAGENAME }}
tag_prefix: "docker-${{ inputs.DOCKER_IMAGENAME }}-"
if: "${{ inputs.PUSH_IMAGE }}"
- name: Build image and push to Docker Hub and GitHub Container Registry
id: docker_build
uses: docker/build-push-action@v3
with:
# relative path to the place where source code with Dockerfile is located
context: docker/${{ inputs.DOCKER_ORGANIZATION_NAME }}/${{ inputs.DOCKER_IMAGENAME }}
# Note: tags has to be all lower-case
tags: |
${{ inputs.DOCKER_ORGANIZATION_NAME }}/${{ inputs.DOCKER_IMAGENAME }}:latest,
${{ inputs.DOCKER_ORGANIZATION_NAME }}/${{ inputs.DOCKER_IMAGENAME }}:v${{ steps.tag_step.outputs.version }}
# build on feature branches, push only on main branch
push: ${{ inputs.PUSH_IMAGE }}
build-args: "VERSION=${{ steps.tag_step.outputs.version }}"
platforms: ${{ inputs.PLATFORMS }}