-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoci-copy-to-docker.sh
executable file
·242 lines (197 loc) · 12.2 KB
/
oci-copy-to-docker.sh
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#!/bin/ash
HERE=$(pwd)
if [ -z "$DOCKER_USER" ]; then
echo "You need to export the docker.io registry username e.g."
echo "export DOCKER_USER=\"something\""
exit
fi
if [ -z "$DOCKER_PW" ]; then
echo "You need to export the docker.io registry password e.g."
echo "export DOCKER_PW=\"something\""
exit
fi
if [ $# -lt 3 ];
then
echo "+ $0: Too few arguments!"
echo "+ use something like:"
echo "+ $0 <image name> <container name> <tag> <image container name> <machine name> <tmpdir>"
echo "+ $0 app-container-image-python3-mastermind-oci app-container-python3-mastermind-oci latest"
echo "+ $0 app-container-image-python3-mqttbrokerclient-oci app-container-python3-mqttbrokerclient-oci latest"
echo "+ $0 app-container-image-python3-data-collector-oci app-container-python3-data-collector-oci latest"
echo "+ $0 app-container-image-python3-nmap-srv-oci app-container-python3-nmap-srv-oci latest"
echo "+ $0 app-container-image-mosquitto-oci app-container-mosquitto-oci latest"
echo "+ $0 app-container-image-redis-oci app-container-redis-oci latest"
echo "+ $0 app-container-image-tensorflow-oci app-container-tensorflow-oci latest container-x86-64-tensorflow"
echo "+ $0 app-container-image-java-oci app-container-java-oci latest container-x86-64-java"
echo "+ $0 app-container-image-java-examples-oci app-container-java-examples-oci latest container-x86-64-java"
echo "+ $0 app-container-image-tensorflow-examples-oci app-container-tensorflow-examples-oci latest container-x86-64-tensorflow"
echo "+ $0 app-container-image-influxdb-prebuilt-oci app-container-influxdb-prebuilt-oci latest container-x86-64-golang"
echo "+ $0 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
echo "+ $0 app-container-image-lighttpd-oci-container-arm-v7 oci-lighttpd latest-arm-v7 container-arm-v7 container-arm-v7 tmp"
echo "+ $0 app-container-image-lighttpd-oci-container-x86-64 oci-lighttpd latest-x86-64 container-x86-64 container-x86-64 tmp"
echo "+ $0 app-container-image-telegraf-prebuilt-oci-container-arm-v7 oci-telegraf-prebuilt latest-arm-v7 container-arm-v7-tig container-arm-v7 tmp"
echo "+ $0 app-container-image-telegraf-prebuilt-oci-container-arm-v7 oci-telegraf-prebuilt 1.17.3 container-arm-v7-master container-arm-v7 tmp"
echo "+ $0 app-container-image-telegraf-prebuilt-oci-container-x86-64 oci-telegraf-prebuilt latest-x86-64 container-x86-64-tig container-x86-64 tmp"
echo "+ $0 app-container-image-telegraf-prebuilt-oci-container-arm-v7 oci-telegraf-prebuilt latest-arm-v7 imx6q-phytec-mira-rdk-nand-virt-wic-mc container-arm-v7 tmp-container-arm-v7-resy-container"
echo "+ $0 app-container-image-phoronix-oci-container-arm-v7 oci-phoronix latest-arm-v7 container-arm-v7-phoronix container-arm-v7 tmp"
echo "+ $0 app-container-image-phoronix-oci-container-arm-v7 oci-phoronix latest-arm-v7hf container-arm-v7-phoronix container-arm-v7 tmp"
echo "+ $0 app-container-image-tensorflow-examples-oci-container-imx8mm-lpddr4-evk-ml oci-tensorflow-examples latest-aarch64-armv8a-crc-cortexa53 container-imx8mm-lpddr4-evk-ml-tensorflow-master container-imx8mm-lpddr4-evk-ml tmp"
echo "+ $0 app-container-image-lighttpd-oci-container-x86-64 container-ex-compact-oci-lighttpd-x86-64 latest-x86-64 container-x86-64-ex-compact-oci container-x86-64 tmp"
exit
fi
#####################################################################################################################################################################
# ./oci-copy-to-docker.sh app-container-image-telegraf-prebuilt-oci-container-arm-v7 oci-telegraf-prebuilt latest-arm-v7 container-arm-v7-tig container-arm-v7 tmp
# image name
# container name
# tag
# image container name
# machine name
# tmpdir
#####################################################################################################################################################################
# image name: app-container-image-telegraf-prebuilt-oci-container-arm-v7
# container name: oci-telegraf-prebuilt
# tag: latest-arm-v7
# image container name: container-arm-v7-tig
# machine: container-arm-v7
# if there is a repository on docker hub called:
# docker://docker.io/reliableembeddedsystems/oci-telegraf-prebuilt
# deploy dir: /workdir/build/container-arm-v7-tig/tmp/deploy/images/container-arm-v7/
#####################################################################################################################################################################
#####################################################################################################################################################################
# ./oci-copy-to-docker.sh app-container-image-telegraf-prebuilt-oci-container-arm-v7 oci-telegraf-prebuilt latest-arm-v7 imx6q-phytec-mira-rdk-nand-virt-wic-mc container-arm-v7 tmp-container-arm-v7-resy-container
#####################################################################################################################################################################
# image name: app-container-image-telegraf-prebuilt-oci-container-arm-v7
# container name: oci-telegraf-prebuilt
# tag: latest-arm-v7
# image container name: imx6q-phytec-mira-rdk-nand-virt-wic-mc
# machine: container-arm-v7
# if there is a repository on docker hub called:
# docker://docker.io/reliableembeddedsystems/oci-telegraf-prebuilt
# deploy dir: /workdir/build/imx6q-phytec-mira-rdk-nand-virt-wic-mc/tmp-container-arm-v7-resy-container/deploy/images/container-arm-v7/
#####################################################################################################################################################################
IMAGE="$1"
CONTAINER="$2"
TAG="$3"
IMAGE_CONTAINER_NAME="$4"
MACHINE="$5"
TMPDIR="$6"
echo "image name: ${IMAGE}"
echo "container name: ${CONTAINER}"
echo "tag: ${TAG}"
#echo "docker user: ${DOCKER_USER}"
#echo "docker password: ${DOCKER_PW}"
echo "image container name (only used for deploy dir): ${IMAGE_CONTAINER_NAME}"
echo "machine (only used for deploy dir): ${MACHINE}"
echo "if there is a repository on docker hub called:"
echo "docker://docker.io/${DOCKER_USER}/${CONTAINER}"
echo "deploy dir: /workdir/build/${IMAGE_CONTAINER_NAME}/${TMPDIR}/deploy/images/${MACHINE}/"
echo "press <ENTER>"
read r
set -x
cd /workdir/build/${IMAGE_CONTAINER_NAME}/${TMPDIR}/deploy/images/${MACHINE}/
set +x
retVal=$?
if [ $retVal -ne 0 ]; then
echo "can not cd into"
/workdir/build/${IMAGE_CONTAINER_NAME}/${TMPDIR}/deploy/images/${MACHINE}/
echo "press <ENTER>"
read r
exit $retVal
fi
set -x
# check first, we clean up below if needed
HERE_AGAIN=$(pwd)
rm -rf unzip && mkdir unzip
cd unzip
# untar the OCI stuff
ls -la ../${IMAGE}*.tar
tar xvf ../${IMAGE}*.tar
OCI="$(ls | grep rootfs-oci)"
#echo "+ vi ${OCI}/index.json"
#echo "press <ENTER>"
#read r
#vi ${OCI}/index.json
set +x
# hack to fix wrong entry in index.json for armv7
#sed -i 's/\\"variant\\"/"variant"/g' ${OCI}/index.json
#skopeo --debug copy --dest-creds ${DOCKER_USER}:${DOCKER_PW} oci:${OCI}:latest docker://${DOCKER_USER}/${CONTAINER}
#skopeo --debug copy -f v2s2 --dest-creds ${DOCKER_USER}:${DOCKER_PW} oci:${OCI}:latest docker://${DOCKER_USER}/${CONTAINER}
#skopeo --debug copy -f v2s2 --dest-creds ${DOCKER_USER}:${DOCKER_PW} oci:${OCI}:latest docker://${DOCKER_USER}/${CONTAINER}:${TAG}
#skopeo copy -f v2s2 --dest-creds ${DOCKER_USER}:${DOCKER_PW} oci:${OCI}:latest docker://${DOCKER_USER}/${CONTAINER}
# check local oci image which yocto created - good
original_json=$(skopeo inspect oci:${OCI} | jq '.Layers')
#skopeo inspect --raw oci:${OCI} | jq
# check already uploaded (previous) docker container on docker hub - good
changed_json=$(skopeo inspect docker://${DOCKER_USER}/${CONTAINER}:${TAG} | jq '.Layers')
#skopeo inspect --raw docker://${DOCKER_USER}/${CONTAINER}:${TAG} | jq
#skopeo inspect docker-archive:${CONTAINER}-${TAG}.skopeo.tar:${DOCKER_USER}/${CONTAINER} | jq '.Layers'
echo ${original_json} > aa.json
echo ${changed_json} > bb.json
diff aa.json bb.json
# if the above are identical, there is no need to go any further, I guess
if [ $? -eq 0 ]
then
set +x
echo "the oci container created by Yocto:"
echo " oci:${OCI}"
echo "and what's on docker hub:"
echo " docker://${DOCKER_USER}/${CONTAINER}:${TAG}"
echo "seem to be idential - no need to upload again"
echo "press <ENTER> to go on"
read r
exit 0
fi
# if they are not identical, we need to upload a new one
echo "looks like something is different now - might be only meta-data"
echo "press <ENTER> to go on"
read r
set -x
# clean up
cd ${HERE_AGAIN}
rm -rf unzip && mkdir unzip && cd unzip
# untar the OCI stuff
ls -la ../${IMAGE}*.tar
tar xvf ../${IMAGE}*.tar
OCI="$(ls)"
TIMESTAMP=$(date +%Y-%m-%d_%H-%M-%S)
# --> create a local docker-archive - note docker-archive digest is different from above
if [ -f ${CONTAINER}-${TAG}.skopeo.tar ]; then
rm -f ${CONTAINER}-${TAG}.skopeo.tar
fi
skopeo copy oci:${OCI} docker-archive:${CONTAINER}-${TAG}.skopeo.tar.docker-archive:${DOCKER_USER}/${CONTAINER}
# also create one with timestamp
skopeo copy oci:${OCI}:latest docker-archive:${CONTAINER}-${TAG}-${TIMESTAMP}.skopeo.tar:${DOCKER_USER}/${CONTAINER}
# <-- create a local docker-archive - note docker-archive digest is different from above
# --> check locally converted oci -> docker-archive image - MEEEHH docker-archive adds something so we get a new checksum
# skopeo inspect docker-archive:${CONTAINER}-${TAG}.skopeo.tar | jq '.Layers'
# skopeo inspect --raw docker-archive:${CONTAINER}-${TAG}.skopeo.tar.docker-archive | jq
# <-- check locally converted oci -> docker-archive image - MEEEHH docker-archive adds something so we get a new checksum
# --> let's pull docker-archive from docker hub - MEEEHH docker-archive adds something so we get a new checksum
# skopeo copy docker://${DOCKER_USER}/${CONTAINER}:${TAG} docker-archive:${CONTAINER}-${TAG}.skopeo.tar.docker-archive-from-docker:${DOCKER_USER}/${CONTAINER}
# skopeo inspect --raw docker-archive:${CONTAINER}-${TAG}.skopeo.tar.docker-archive-from-docker | jq
# <-- let's pull docker-archive from docker hub - MEEEHH docker-archive adds something so we get a new checksum
# --> let's pull oci image from docker hub - now we are good with checksum ;)
# skopeo copy docker://${DOCKER_USER}/${CONTAINER}:${TAG} oci:${CONTAINER}-${TAG}.skopeo.tar.oci-from-docker:${DOCKER_USER}/${CONTAINER}
# skopeo inspect --raw oci:${CONTAINER}-${TAG}.skopeo.tar.oci-from-docker | jq
# <-- let's pull oci image from docker hub - now we are good with checksum ;)
#skopeo inspect docker://${DOCKER_USER}/${CONTAINER}:${TAG} | jq '.Layers'
#read r
# --> upload new image to docker hub
skopeo --debug copy -f v2s2 --dest-creds ${DOCKER_USER}:${DOCKER_PW} oci:${OCI}:latest docker://${DOCKER_USER}/${CONTAINER}:${TAG}
# also with timestamp tag
skopeo --debug copy -f v2s2 --dest-creds ${DOCKER_USER}:${DOCKER_PW} oci:${OCI}:latest docker://${DOCKER_USER}/${CONTAINER}:${TAG}-${TIMESTAMP}
# <-- upload new image to docker hub
# --> check our newly created stuff
# check local oci image which yocto created - good
skopeo inspect oci:${OCI} | jq '.Layers'
#skopeo inspect --raw oci:${OCI} | jq
# check already uploaded (previous) docker container on docker hub - good
skopeo inspect docker://${DOCKER_USER}/${CONTAINER}:${TAG} | jq '.Layers'
#skopeo inspect --raw docker://${DOCKER_USER}/${CONTAINER}:${TAG} | jq
# <-- check out newly created stuff
set +x
cd ${HERE}
echo "try:"
echo "docker pull docker.io/${DOCKER_USER}/${CONTAINER}"
echo "docker pull docker.io/${DOCKER_USER}/${CONTAINER}:${TAG}"
echo "docker pull docker.io/${DOCKER_USER}/${CONTAINER}:${TAG}-${TIMESTAMP}"