-
Notifications
You must be signed in to change notification settings - Fork 18
114 lines (104 loc) · 4.09 KB
/
deploy-docker.yaml
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
################################################################################
# Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License, Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# SPDX-License-Identifier: Apache-2.0
################################################################################
name: Deploy - Docker Image
on:
workflow_dispatch:
inputs:
imageName:
required: true
type: string
description: Name the built image should get
dockerfilePath:
required: true
type: string
description: Path to where the Dockerfile to build is
workflow_call:
inputs:
imageName:
required: true
type: string
description: Name the built image should get
dockerfilePath:
required: true
type: string
description: Path to where the Dockerfile to build is
env:
IMAGE_NAMESPACE: "tractusx"
IMAGE_NAME: ${{ inputs.imageName }}
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Extract Maven Project Version
id: pomVersion
run: |
POM_VERSION=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' -B --non-recursive exec:exec)
echo "version=$POM_VERSION" >> $GITHUB_OUTPUT
- name: Parse semantic version from string
id: semVer
uses: release-kit/semver@v2
with:
string: 'v${{ steps.pomVersion.outputs.version }}'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5
- name: Create Docker Tags
id: dockerTags
run: |
FULL_IMAGE_NAME="${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }}"
SUFFIX="${{ steps.semVer.outputs.prerelease && '-' || '' }}${{ steps.semVer.outputs.prerelease }}"
MAJOR="${{ steps.semVer.outputs.major }}"
MINOR="${MAJOR}.${{ steps.semVer.outputs.minor }}"
PATCH="${MINOR}.${{ steps.semVer.outputs.patch }}"
LATEST_TAG="${FULL_IMAGE_NAME}:latest${SUFFIX}"
MAJOR_TAG="${FULL_IMAGE_NAME}:${MAJOR}${SUFFIX}"
MINOR_TAG="${FULL_IMAGE_NAME}:${MINOR}${SUFFIX}"
PATCH_TAG="${FULL_IMAGE_NAME}:${PATCH}${SUFFIX}"
if ${{ steps.semVer.outputs.prerelease == 'SNAPSHOT' && true || false }}; then
ALL_TAGS="${LATEST_TAG},${PATCH_TAG}"
else
if ${{ steps.semVer.outputs.prerelease && true || false }}; then
ALL_TAGS="${PATCH_TAG}"
else
ALL_TAGS="${LATEST_TAG},${MAJOR_TAG},${MINOR_TAG},${PATCH_TAG}"
fi
fi
echo "tags=${ALL_TAGS}" >> $GITHUB_OUTPUT
echo "tags=${ALL_TAGS}"
- name: DockerHub login
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64, linux/arm64
push: true
file: ${{ inputs.dockerfilePath }}/Dockerfile
tags: ${{ steps.dockerTags.outputs.tags }}
- name: Update Docker Hub description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
repository: ${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }}
readme-filepath: ${{ inputs.dockerfilePath }}/DOCKER_NOTICE.md