generated from andygruber/build-winccoa-docker-image
-
-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (110 loc) · 4.42 KB
/
generate-winccoa-image.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
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
name: Generate and upload WinCC OA image
on:
workflow_dispatch:
push:
branches: [ "main", "release/*", "develop", "develop/*" ]
# pull_request:
# branches: [ "main", "release/*", "develop", "develop/*" ]
release:
types: [published]
jobs:
get_environment:
runs-on: ubuntu-latest
steps:
- name: Define the used environment
id: env_check
run: |
ENV_NAME=staging
if [[ "${{ github.event_name }}" == "release" ]]; then
ENV_NAME=staging
elif [[ "${{ github.event_name }}" == "pull_request" ]]; then
ENV_NAME=staging
else
ENV_NAME=staging
fi
echo "Chosen environment: ${ENV_NAME}"
echo "env_name=${ENV_NAME}" >> $GITHUB_OUTPUT
outputs:
env_name: ${{ steps.env_check.outputs.env_name }}
generate-winccoa-image:
needs: [get_environment]
runs-on: ubuntu-latest
environment:
name: ${{ needs.get_environment.outputs.env_name }}
steps:
- name: Set up Git repository
uses: actions/checkout@v3
- name: Download current WinCC OA version
env:
ETM_USERNAME: ${{ secrets.ETM_USERNAME }}
ETM_PASSWORD: ${{ secrets.ETM_PASSWORD }}
run: scripts/download.sh
- name: Extract version information
id: get_version
run: |
zip_file=$(ls *.zip | head -n 1)
if [ -f "$zip_file" ]; then
echo "ZIP file found: $zip_file"
[[ $zip_file =~ ([0-9]+)\.([0-9]+)_linux_debian_x86_64_P([0-9]+)\.?([0-9]*)\.zip ]]
major_version=${BASH_REMATCH[1]}
minor_version=${BASH_REMATCH[2]}
patch_version=$(echo ${BASH_REMATCH[3]} | sed 's/^0*//') # Remove leading zeros
revision=${BASH_REMATCH[4]#\.} # Remove leading dot from the revision
if [ "$revision" != "0" ] && [ ! -z "$revision" ]; then
version_string="$major_version.$minor_version.$patch_version.$revision"
else
version_string="$major_version.$minor_version.$patch_version"
fi
echo "Version info found: ${version_string}"
echo "major_version=${major_version}" >> $GITHUB_OUTPUT
echo "minor_version=${minor_version}" >> $GITHUB_OUTPUT
echo "patch_version=${patch_version}" >> $GITHUB_OUTPUT
echo "revision=${revision}" >> $GITHUB_OUTPUT
echo "version=${version_string}" >> $GITHUB_OUTPUT
else
echo "No ZIP file found"
exit 1
fi
- name: Unzip data
run: |
mkdir data && cd data && \
unzip ../*.zip
- name: Prepare data for Docker image build
run: |
# copy files provided from WinCC OA package for our custom Docker build
cp data/docker-entrypoint.sh data/Dockerfile build-docker/
# patch Dockerfile so it does not copy and install the packages, but only does preparation
scripts/patchDockerfile.sh build-docker/Dockerfile
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Docker build setup
working-directory: ./build-docker
run: |
docker network create winccoarepo
docker compose up -d
# wait until repo data is generated
docker compose wait create-repo
- name: Docker build preparation image
working-directory: ./build-docker
run: |
DOCKER_BUILDKIT=0 docker build --no-cache --network=winccoarepo -t winccoaprepare:temp .
- name: Docker build and push images
working-directory: ./build-docker
run: |
# specify targets from Dockerfile_install here
for target in api server uiserver full; do
tag_suffix=${target}
image_name="${DOCKER_IMAGE}:v${{ steps.get_version.outputs.version }}-${tag_suffix}"
DOCKER_BUILDKIT=0 docker build --network=winccoarepo --build-arg BASE_IMAGE=winccoaprepare:temp --target winccoa${target} --tag ${image_name} -f Dockerfile_install .
docker push ${image_name}
done
env:
DOCKER_IMAGE: ${{ vars.DOCKER_IMAGE }}
- name: Docker build teardown
working-directory: ./build-docker
run: |
docker compose down
docker network rm winccoarepo