Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit 186b2eb

Browse files
committed
Aligned with PowerShell version deploy-all.ps1
1 parent 93c86fc commit 186b2eb

File tree

1 file changed

+28
-25
lines changed

1 file changed

+28
-25
lines changed

k8s/helm/deploy-all.sh

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,29 @@ Parameters:
2020
When --use-local-k8s is specified the external DNS is automatically set to localhost.
2121
-h | --help
2222
Displays this help text and exits the script.
23+
--image-build
24+
Build images (default is to not build all images).
25+
--image-push
26+
Upload images to the container registry (default is not pushing to the custom registry)
2327
-n | --app-name <the name of the app>
2428
Specifies the name of the application (default: eshop).
29+
--namespace <namespace name>
30+
Specifies the namespace name to deploy the app. If it doesn't exists it will be created (default: eshop).
2531
-p | --docker-password <docker password>
2632
The Docker password used to logon to the custom registry, supplied using the -r parameter.
2733
-r | --registry <container registry>
2834
Specifies the container registry to use (required), e.g. myregistry.azurecr.io.
2935
--skip-clean
3036
Do not clean the Kubernetes cluster (default is to clean the cluster).
31-
--skip-image-build
32-
Do not build images (default is to build all images).
33-
--skip-image-push
34-
Do not upload images to the container registry (just run the Kubernetes deployment portion).
35-
Default is to push the images to the container registry.
3637
--skip-infrastructure
3738
Do not deploy infrastructure resources (like sql-data, no-sql or redis).
3839
This is useful for production environments where infrastructure is hosted outside the Kubernetes cluster.
3940
-t | --tag <docker image tag>
40-
The tag used for the newly created docker images. Default: newly created, date-based timestamp, with 1-minute resolution.
41+
The tag used for the newly created docker images. Default: latest.
4142
-u | --docker-username <docker username>
4243
The Docker username used to logon to the custom registry, supplied using the -r parameter.
4344
--use-local-k8s
4445
Deploy to a locally installed Kubernetes (default: false).
45-
--namespace <namespace name>
46-
Specifies the namespace name to deploy the app. If it doesn't exists it will be created (default: eshop).
4746
4847
It is assumed that the Kubernetes cluster has been granted access to the container registry.
4948
If using AKS and ACR see link for more info:
@@ -61,15 +60,15 @@ END
6160
app_name='eshop'
6261
aks_name=''
6362
aks_rg=''
64-
build_images='yes'
63+
build_images=''
6564
clean='yes'
6665
build_solution=''
6766
container_registry=''
6867
docker_password=''
6968
docker_username=''
7069
dns=''
71-
image_tag=$(date '+%Y%m%d%H%M')
72-
push_images='yes'
70+
image_tag='latest'
71+
push_images=''
7372
skip_infrastructure=''
7473
use_local_k8s=''
7574
namespace='eshop'
@@ -94,10 +93,10 @@ while [[ $# -gt 0 ]]; do
9493
container_registry="$2"; shift 2;;
9594
--skip-clean )
9695
clean=''; shift ;;
97-
--skip-image-build )
98-
build_images=''; shift ;;
99-
--skip-image-push )
100-
push_images=''; shift ;;
96+
--image-build )
97+
build_images='yes'; shift ;;
98+
--image-push )
99+
push_images='yes'; shift ;;
101100
--skip-infrastructure )
102101
skip_infrastructure='yes'; shift ;;
103102
-t | --tag )
@@ -141,17 +140,17 @@ if [[ -n $container_registry ]]; then
141140
docker login -u $docker_username -p $docker_password $container_registry
142141
fi
143142

144-
145143
if [[ $push_images ]]; then
146144
echo "#################### Pushing images to the container registry ####################"
147145
services=(basket.api catalog.api identity.api ordering.api marketing.api payment.api locations.api webmvc webspa webstatus)
148146

147+
if [[ -z "$(docker image ls -q --filter=reference=eshop/$service:$image_tag)" ]]; then
148+
image_tag=linux-$image_tag
149+
fi
150+
149151
for service in "${services[@]}"
150152
do
151153
echo "Pushing image for service $service..."
152-
if [[ -z "$(docker image ls -q --filter=reference=eshop/$service:$image_tag)" ]]; then
153-
image_tag=linux-$image_tag
154-
fi
155154
docker tag "eshop/$service:$image_tag" "$container_registry/$service:$image_tag"
156155
docker push "$container_registry/$service:$image_tag"
157156
done
@@ -175,8 +174,10 @@ if [[ $dns == "aks" ]]; then
175174

176175
echo "Getting AKS cluster $aks_name AKS (in resource group $aks_rg)"
177176
# JMESPath queries are case sensitive and httpapplicationrouting can be lowercase sometimes
178-
jmespath_dnsqueries=(addonProfiles.httpApplicationRouting.config.HTTPApplicationRoutingZoneName \
179-
addonProfiles.httpapplicationrouting.config.HTTPApplicationRoutingZoneName)
177+
jmespath_dnsqueries=(\
178+
addonProfiles.httpApplicationRouting.config.HTTPApplicationRoutingZoneName \
179+
addonProfiles.httpapplicationrouting.config.HTTPApplicationRoutingZoneName \
180+
)
180181
for q in "${jmespath_dnsqueries[@]}"
181182
do
182183
dns="$(az aks show -n $aks_name -g $aks_rg --query $q -o tsv)"
@@ -187,6 +188,7 @@ if [[ $dns == "aks" ]]; then
187188
exit 1
188189
fi
189190
echo "DNS base found is $dns. Will use $aks_name.$dns for the app!"
191+
dns="$aks_name.$dns"
190192
fi
191193

192194
# Initialization & check commands
@@ -199,8 +201,9 @@ if [[ $clean ]]; then
199201
if [[ -z $(helm ls -q --namespace $namespace) ]]; then
200202
echo "No previous releases found"
201203
else
202-
helm delete --purge $(helm ls -q --namespace $namespace)
204+
helm delete --purge $(helm ls -q --namespace $namespace)
203205
echo "Previous releases deleted"
206+
waitsecs=10; while [ $waitsecs -gt 0 ]; do echo -ne "$waitsecs\033[0K\r"; sleep 1; : $((waitsecs--)); done
204207
fi
205208
fi
206209

@@ -212,17 +215,17 @@ if [[ !$skip_infrastructure ]]; then
212215
for infra in "${infras[@]}"
213216
do
214217
echo "Installing infrastructure: $infra"
215-
helm install --namespace $namespace --values app.yaml --values inf.yaml --values $ingress_values_file --set app.name=$app_name --set inf.k8s.dns=$dns --name="$app_name-$infra" $infra
218+
helm install --namespace $namespace --set "ingress.hosts={$dns}" --values app.yaml --values inf.yaml --values $ingress_values_file --set app.name=$app_name --set inf.k8s.dns=$dns --name="$app_name-$infra" $infra
216219
done
217220
fi
218221

219222
for chart in "${charts[@]}"
220223
do
221224
echo "Installing: $chart"
222225
if [[ $use_custom_registry ]]; then
223-
helm install --namespace $namespace --set ingress.hosts[0]=$dns --set inf.registry.server=$container_registry --set inf.registry.login=$docker_username --set inf.registry.pwd=$docker_password --set inf.registry.secretName=eshop-docker-scret --values app.yaml --values inf.yaml --values $ingress_values_file --set app.name=$app_name --set inf.k8s.dns=$dns --set image.tag=$image_tag --set image.pullPolicy=Always --name="$app_name-$chart" $chart
226+
helm install --namespace $namespace --set "ingress.hosts={$dns}" --set inf.registry.server=$container_registry --set inf.registry.login=$docker_username --set inf.registry.pwd=$docker_password --set inf.registry.secretName=eshop-docker-scret --values app.yaml --values inf.yaml --values $ingress_values_file --set app.name=$app_name --set inf.k8s.dns=$dns --set image.tag=$image_tag --set image.pullPolicy=Always --name="$app_name-$chart" $chart
224227
elif [[ $chart != "eshop-common" ]]; then # eshop-common is ignored when no secret must be deployed
225-
helm install --namespace $namespace --set ingress.hosts[0]=$dns --values app.yaml --values inf.yaml --values $ingress_values_file --set app.name=$app_name --set inf.k8s.dns=$dns --set image.tag=$image_tag --set image.pullPolicy=Always --name="$app_name-$chart" $chart
228+
helm install --namespace $namespace --set "ingress.hosts={$dns}" --values app.yaml --values inf.yaml --values $ingress_values_file --set app.name=$app_name --set inf.k8s.dns=$dns --set image.tag=$image_tag --set image.pullPolicy=Always --name="$app_name-$chart" $chart
226229
fi
227230
done
228231

0 commit comments

Comments
 (0)