-
Notifications
You must be signed in to change notification settings - Fork 4
104 lines (96 loc) · 4.44 KB
/
docker-build.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
name: Build Docker and Push
on:
push:
branches:
- "**"
tags-ignore:
- '**'
workflow_dispatch:
jobs:
docker-build:
name: Docker Build and Push
runs-on: ubuntu-latest
env:
NAMESPACE: ${{ secrets.docker_hub_organisation || 'openg2p' }}
OS_KAFKA_CONNECTOR_SERVICE_NAME: reporting-opensearch-kafka-connector
REPORTING_INIT_SERVICE_NAME: reporting-init-shell-tools
steps:
- uses: actions/checkout@v3
- id: files
uses: jitterbit/get-changed-files@v1
- name: Docker build OS Kafka Connector
run: |
OS_KAFKA_CONNECTOR_DOCKER_BUILD="false"
for changed_file in ${{ steps.files.outputs.all }}; do
if [[ ${changed_file} =~ ^opensearch-kafka-connector ]]; then
OS_KAFKA_CONNECTOR_DOCKER_BUILD="true"
break
fi
done
if [ "$OS_KAFKA_CONNECTOR_DOCKER_BUILD" != "true" ]; then
echo "Nothing to build!"
exit 0;
fi
BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')
OS_KAFKA_CONNECTOR_IMAGE_ID=$NAMESPACE/$OS_KAFKA_CONNECTOR_SERVICE_NAME
# Change all uppercase to lowercase
OS_KAFKA_CONNECTOR_IMAGE_ID=$(echo $OS_KAFKA_CONNECTOR_IMAGE_ID | tr '[A-Z]' '[a-z]')
OS_KAFKA_CONNECTOR_VERSION=$BRANCH_NAME
if [[ $BRANCH_NAME == master || $BRANCH_NAME == main ]]; then
OS_KAFKA_CONNECTOR_VERSION=develop
fi
echo OS_KAFKA_CONNECTOR_IMAGE_ID=$OS_KAFKA_CONNECTOR_IMAGE_ID
echo OS_KAFKA_CONNECTOR_VERSION=$OS_KAFKA_CONNECTOR_VERSION
echo OS_KAFKA_CONNECTOR_IMAGE_ID=$OS_KAFKA_CONNECTOR_IMAGE_ID >> $GITHUB_ENV
echo OS_KAFKA_CONNECTOR_VERSION=$OS_KAFKA_CONNECTOR_VERSION >> $GITHUB_ENV
cd opensearch-kafka-connector
docker build . \
--file Dockerfile \
--tag $OS_KAFKA_CONNECTOR_IMAGE_ID:$OS_KAFKA_CONNECTOR_VERSION
if [[ '${{ secrets.docker_hub_token }}' != '' && '${{ secrets.docker_hub_actor }}' != '' ]]; then
export OS_KAFKA_CONNECTOR_DOCKER_PUSH="true"
echo OS_KAFKA_CONNECTOR_DOCKER_PUSH=$OS_KAFKA_CONNECTOR_DOCKER_PUSH >> $GITHUB_ENV
fi
- name: Docker push OS Kafka Connector
if: env.OS_KAFKA_CONNECTOR_DOCKER_PUSH == 'true'
run: |
echo "${{ secrets.docker_hub_token }}" | docker login -u ${{ secrets.docker_hub_actor }} --password-stdin
docker push ${{ env.OS_KAFKA_CONNECTOR_IMAGE_ID }}:${{ env.OS_KAFKA_CONNECTOR_VERSION }}
- name: Docker build Reporting Init
run: |
REPORTING_INIT_DOCKER_BUILD="false"
for changed_file in ${{ steps.files.outputs.all }}; do
if [[ ${changed_file} =~ ^reporting-init-docker ]]; then
REPORTING_INIT_DOCKER_BUILD="true"
break
fi
done
if [ "$REPORTING_INIT_DOCKER_BUILD" != "true" ]; then
echo "Nothing to build!"
exit 0;
fi
BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')
REPORTING_INIT_IMAGE_ID=$NAMESPACE/$REPORTING_INIT_SERVICE_NAME
# Change all uppercase to lowercase
REPORTING_INIT_IMAGE_ID=$(echo $REPORTING_INIT_IMAGE_ID | tr '[A-Z]' '[a-z]')
REPORTING_INIT_VERSION=$BRANCH_NAME
if [[ $BRANCH_NAME == master || $BRANCH_NAME == main ]]; then
REPORTING_INIT_VERSION=develop
fi
echo REPORTING_INIT_IMAGE_ID=$REPORTING_INIT_IMAGE_ID
echo REPORTING_INIT_VERSION=$REPORTING_INIT_VERSION
echo REPORTING_INIT_IMAGE_ID=$REPORTING_INIT_IMAGE_ID >> $GITHUB_ENV
echo REPORTING_INIT_VERSION=$REPORTING_INIT_VERSION >> $GITHUB_ENV
cd reporting-init-docker
docker build . \
--file Dockerfile \
--tag $REPORTING_INIT_IMAGE_ID:$REPORTING_INIT_VERSION
if [[ '${{ secrets.docker_hub_token }}' != '' && '${{ secrets.docker_hub_actor }}' != '' ]]; then
export REPORTING_INIT_DOCKER_PUSH="true"
echo REPORTING_INIT_DOCKER_PUSH=$REPORTING_INIT_DOCKER_PUSH >> $GITHUB_ENV
fi
- name: Docker push Reporting Init
if: env.REPORTING_INIT_DOCKER_PUSH == 'true'
run: |
echo "${{ secrets.docker_hub_token }}" | docker login -u ${{ secrets.docker_hub_actor }} --password-stdin
docker push ${{ env.REPORTING_INIT_IMAGE_ID }}:${{ env.REPORTING_INIT_VERSION }}