|
1 |
| -#!/bin/sh |
2 |
| - |
3 |
| -display_help() { |
4 |
| - echo "Usage: $0 -i image_name -v version -r registry -a architecture " >&2 |
5 |
| - echo |
6 |
| - echo " -i image_name Specify the image name, for example: bluetooth-AoA-example-build-env" |
7 |
| - echo " -v version Specify the version of docker image, for example: 1.0.0" |
8 |
| - echo " -r registry Specify the Docker registry to push the image to (optional) example: lx0017637.silabs.com:5000" |
9 |
| - echo " If internal registry is used, SonarQube will be included." |
10 |
| - echo " -a architecture Specify the architecture, for example: x86_64 or aarch64" |
11 |
| - echo |
12 |
| - exit 1 |
13 |
| -} |
14 |
| - |
15 |
| -image_name="" |
16 |
| -version="1.0.0" |
17 |
| -registry="none" |
18 |
| -architecture="x86_64" |
19 |
| -run_sonarqube_scanner="false" |
20 |
| - |
21 |
| -# Process the options |
22 |
| -while getopts ":h:i:v:r:a:" opt; do |
23 |
| - case $opt in |
24 |
| - h) display_help |
25 |
| - exit;; |
26 |
| - i) image_name="$OPTARG";; |
27 |
| - v) version="$OPTARG";; |
28 |
| - r) registry="$OPTARG";; |
29 |
| - a) architecture="$OPTARG";; |
30 |
| - \?) echo "Invalid option -$OPTARG" >&2 |
31 |
| - display_help |
32 |
| - exit 1;; |
33 |
| - :) echo "Option -$OPTARG requires an argument." >&2 |
34 |
| - display_help |
35 |
| - exit 1;; |
36 |
| - esac |
37 |
| -done |
38 |
| - |
39 |
| -if [ "$registry" = "lx0017637.silabs.com:5000" ] ; then |
40 |
| - echo "Internal silabs build with: $registry" |
41 |
| - run_sonarqube_scanner="true" |
42 |
| -fi |
43 |
| - |
44 |
| -# Build the Docker image |
45 |
| -echo "Building Docker image: $image_name:$version for architecture: $architecture " |
46 |
| -docker build --build-arg ARCH="$architecture" --build-arg SONARQUBE="$run_sonarqube_scanner" -t "$image_name:$version" -f Dockerfile . |
47 |
| - |
48 |
| -if [ -n "$registry" ] && [ "$registry" != "none" ] ; then |
49 |
| - docker tag "$image_name:$version" "$registry/$image_name:$version" |
50 |
| - docker push "$registry/$image_name:$version" |
51 |
| -else |
52 |
| - echo "Docker registry not specified, skipping tagging and pushing." |
53 |
| -fi |
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +display_help() { |
| 4 | + echo "Usage: $0 -i image_name -v version -r registry -a architecture " >&2 |
| 5 | + echo |
| 6 | + echo " -i image_name Specify the image name, for example: bluetooth-aoa-example-build-env" |
| 7 | + echo " -v version Specify the version of docker image, for example: 1.0.0" |
| 8 | + echo " -r registry Specify the Docker registry to push the image to (optional)" |
| 9 | + echo " If internal registry is used, SonarQube will be included." |
| 10 | + echo " -a architecture Specify the architecture, for example: x86_64 or aarch64" |
| 11 | + echo |
| 12 | + exit 1 |
| 13 | +} |
| 14 | + |
| 15 | +image_name="" |
| 16 | +version="1.0.0" |
| 17 | +registry="none" |
| 18 | +architecture="x86_64" |
| 19 | +run_sonarqube_scanner="false" |
| 20 | + |
| 21 | +# Process the options |
| 22 | +while getopts ":h:i:v:r:a:" opt; do |
| 23 | + case $opt in |
| 24 | + h) display_help |
| 25 | + exit;; |
| 26 | + i) image_name="$OPTARG";; |
| 27 | + v) version="$OPTARG";; |
| 28 | + r) registry="$OPTARG";; |
| 29 | + a) architecture="$OPTARG";; |
| 30 | + \?) echo "Invalid option -$OPTARG" >&2 |
| 31 | + display_help |
| 32 | + exit 1;; |
| 33 | + :) echo "Option -$OPTARG requires an argument." >&2 |
| 34 | + display_help |
| 35 | + exit 1;; |
| 36 | + esac |
| 37 | +done |
| 38 | + |
| 39 | +if [ "$registry" = "lx0017637.silabs.com:5000" ] ; then |
| 40 | + echo "Internal silabs build with: $registry" |
| 41 | + run_sonarqube_scanner="true" |
| 42 | +fi |
| 43 | + |
| 44 | +# Build the Docker image |
| 45 | +echo "Building Docker image: $image_name:$version for architecture: $architecture " |
| 46 | +docker build --build-arg ARCH="$architecture" --build-arg SONARQUBE="$run_sonarqube_scanner" -t "$image_name:$version" -f Dockerfile . |
| 47 | + |
| 48 | +if [ -n "$registry" ] && [ "$registry" != "none" ] ; then |
| 49 | + docker tag "$image_name:$version" "$registry/$image_name:$version" |
| 50 | + docker push "$registry/$image_name:$version" |
| 51 | +else |
| 52 | + echo "Docker registry not specified, skipping tagging and pushing." |
| 53 | +fi |
0 commit comments