Skip to content

Commit 722780a

Browse files
authored
Merge pull request #40 from Bit-Developer/deploy-with-multiple-value-files
Deploy with multiple value files
2 parents fd9e2a4 + fe473d9 commit 722780a

5 files changed

Lines changed: 164 additions & 0 deletions

File tree

Dockerfile-nas

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Usage:
2+
#
3+
# Build image:
4+
# docker build -t jojozhuang/text-compare-angular-nas -f Dockerfile-nas .
5+
#
6+
# Push to docker hub
7+
# docker push jojozhuang/text-compare-angular-nas
8+
9+
# Stage 1, based on Node.js, to build and compile Angular
10+
11+
FROM node:16.10.0-alpine as builder
12+
13+
WORKDIR /ng-app
14+
15+
COPY package*.json tsconfig*.json angular.json ./
16+
COPY ./src ./src
17+
18+
RUN npm ci --quiet && npm run build-nas
19+
20+
# Stage 2, based on Nginx, to have only the compiled app, ready for production with Nginx
21+
22+
FROM nginx:1.19.8-alpine
23+
24+
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
25+
26+
## From ‘builder’ stage copy over the artifacts in dist folder to default nginx public folder
27+
COPY --from=builder /ng-app/dist /usr/share/nginx/html

Dockerfile-prod

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Usage:
2+
#
3+
# Build image:
4+
# docker build -t jojozhuang/text-compare-angular-prod -f Dockerfile-prod .
5+
#
6+
# Push to docker hub
7+
# docker push jojozhuang/text-compare-angular-prod
8+
9+
# Stage 1, based on Node.js, to build and compile Angular
10+
11+
FROM node:16.10.0-alpine as builder
12+
13+
WORKDIR /ng-app
14+
15+
COPY package*.json tsconfig*.json angular.json ./
16+
COPY ./src ./src
17+
18+
RUN npm ci --quiet && npm run build:aot:prod
19+
20+
# Stage 2, based on Nginx, to have only the compiled app, ready for production with Nginx
21+
22+
FROM nginx:1.19.8-alpine
23+
24+
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
25+
26+
## From ‘builder’ stage copy over the artifacts in dist folder to default nginx public folder
27+
COPY --from=builder /ng-app/dist /usr/share/nginx/html

README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,96 @@ kubectl --namespace default port-forward service/compare-helm 8888:80
177177

178178
Then, you are able to access your site through `http://localhost:8888/`.
179179

180+
## Deploy to multiple environments
181+
182+
### Docker images
183+
184+
Create two docker images first, one for `nas`, another for `prod`.
185+
186+
```sh
187+
docker build -t jojozhuang/text-compare-angular-nas -f Dockerfile-nas .
188+
docker build -t jojozhuang/text-compare-angular-prod -f Dockerfile-prod .
189+
```
190+
191+
List all images and make sure `jojozhuang/text-compare-angular-nas` and `jojozhuang/text-compare-angular-prod` are there.
192+
193+
```sh
194+
docker images
195+
REPOSITORY TAG IMAGE ID CREATED SIZE
196+
jojozhuang/text-compare-angular-prod latest 4a53306114f5 4 seconds ago 30.8MB
197+
jojozhuang/text-compare-angular-nas latest ee561a5e50b3 5 hours ago 30.8MB
198+
jojozhuang/text-compare-angular latest ee561a5e50b3 5 hours ago 30.8MB
199+
```
200+
201+
Push to docker hub.
202+
203+
```sh
204+
docker push jojozhuang/text-compare-angular-nas
205+
docker push jojozhuang/text-compare-angular-prod
206+
```
207+
208+
If you don't push them to hub.docker.com, you might get `ErrImagePull` error.
209+
210+
```sh
211+
kubectl get all -n prod
212+
NAME READY STATUS RESTARTS AGE
213+
pod/compare-helm-57f779585d-6c665 0/1 ErrImageNeverPull 0 5s
214+
pod/compare-helm-6c5668997f-kzk9n 0/1 ErrImagePull 0 105s
215+
```
216+
217+
### Environment specified value files
218+
219+
Copy `values.yaml` and create for `nas` and `prod` env.
220+
221+
```sh
222+
kubectl create namespace nas
223+
kubectl create namespace prod
224+
```
225+
226+
Check new namespaces `nas` and `prod` are created.
227+
228+
```sh
229+
kubectl get namespaces
230+
NAME STATUS AGE
231+
bit-developer Active 70m
232+
default Active 6h24m
233+
kube-node-lease Active 6h24m
234+
kube-public Active 6h24m
235+
kube-system Active 6h24m
236+
kubernetes-dashboard Active 6h23m
237+
nas Active 14s
238+
prod Active 13s
239+
```
240+
241+
Install for nas and prod namespaces.
242+
243+
```sh
244+
helm install compare-helm-nas deployment --values deployment/values.yaml -f deployment/values-nas.yaml -n nas
245+
helm install compare-helm-prod deployment --values deployment/values.yaml -f deployment/values-prod.yaml -n prod
246+
```
247+
248+
List all namespaces.
249+
250+
```sh
251+
helm ls --all-namespaces
252+
NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
253+
compare-helm default 6 2024-01-07 21:49:34.420836 -0800 PST deployed deployment-0.1.0 1.16.0
254+
compare-helm-nas nas 1 2024-01-07 22:10:09.473106 -0800 PST deployed deployment-0.1.0 1.16.0
255+
compare-helm-prod prod 1 2024-01-07 22:10:20.00086 -0800 PST deployed deployment-0.1.0 1.16.0
256+
```
257+
258+
```sh
259+
kubectl get all -n prod
260+
kubectl describe pod compare-helm-77ddc9bc6b-xf96c -n prod
261+
```
262+
263+
```sh
264+
helm upgrade compare-helm-nas deployment --values deployment/values.yaml -f deployment/values-nas.yaml -n nas
265+
helm upgrade compare-helm-prod deployment --values deployment/values.yaml -f deployment/values-prod.yaml -n prod
266+
```
267+
268+
Start nas service and prod service seperately and access `http://localhost:8888/`. You will see the env name on the home page is shown correctly, from `nas` to `production`.
269+
180270
- [How to Create Helm Charts - The Ultimate Guide](https://www.youtube.com/watch?v=jUYNS90nq8U&ab_channel=DevOpsJourney)
181271

182272
# Deployment

deployment/values-nas.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace: nas
2+
3+
configmap:
4+
name: compare-configmap
5+
data:
6+
ENV_NAME: 'NAS'
7+
8+
image:
9+
name: jojozhuang/text-compare-angular-nas
10+
tag: latest

deployment/values-prod.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace: prod
2+
3+
configmap:
4+
name: compare-configmap
5+
data:
6+
ENV_NAME: 'PROD'
7+
8+
image:
9+
name: jojozhuang/text-compare-angular-prod
10+
tag: latest

0 commit comments

Comments
 (0)