hwakabh / 6ow3idgirl.com

Official Homepage of 6ow3idgirl
https://6ow3idgirl.com/
MIT License
0 stars 0 forks source link

deploy: implement GHA with replacing Cloud Build #41

Closed hwakabh closed 8 months ago

hwakabh commented 8 months ago

AsIs

Currently we are using Google Cloud build for deploying application, but it is deactivated on the platform side. Since this application will run on GKE, we can simply use GitHub Actions and build the container image for serve from GitHub packages.

ToDo

hwakabh commented 8 months ago

Confirmed that container image build by build packs has been uploaded to GHCR as GitHub Packages. Evidences from logs of executing pack commands in local environment:

24-03-01 16:20:14 git/6ow3idGirl [ci/41/actions] % pack build ghcr.io/hwakabh/6ow3idgirl:latest \
--builder gcr.io/buildpacks/builder:latest \
--path . \
--clear-cache \
--env GOOGLE_NODEJS_VERSION=18.12.0 \
--env GOOGLE_RUNTIME=nodejs
# (...)
===> ANALYZING
[analyzer] Timer: Analyzer started at 2024-03-01T07:20:25Z
[analyzer] Timer: Analyzer ran for 768.088µs and ended at 2024-03-01T07:20:25Z
===> DETECTING
[detector] Timer: Detector started at 2024-03-01T07:20:26Z
[detector] 3 of 5 buildpacks participating
[detector] google.nodejs.runtime    1.0.0
[detector] google.nodejs.npm        1.1.0
[detector] google.utils.label-image 0.0.2
[detector] Timer: Detector ran for 730.157767ms and ended at 2024-03-01T07:20:27Z
===> RESTORING
[restorer] Timer: Restorer started at 2024-03-01T07:20:27Z
[restorer] Skipping buildpack layer analysis
[restorer] Timer: Restorer ran for 1.383383ms and ended at 2024-03-01T07:20:27Z
===> BUILDING
[builder] Timer: Builder started at 2024-03-01T07:20:27Z
[builder] === Node.js - Runtime (google.nodejs.runtime@1.0.0) ===
[builder] Using runtime version from GOOGLE_NODEJS_VERSION: 18.12.0
[builder] ***** CACHE MISS: "nodejs"
[builder] Installing Node.js v18.12.0.
[builder] 2024/03/01 07:20:27 [DEBUG] GET https://dl.google.com/runtimes/ubuntu2204/nodejs/nodejs-18.12.0.tar.gz
[builder] === Node.js - Npm (google.nodejs.npm@1.1.0) ===
[builder] ***** CACHE MISS: "npm_modules"
[builder] Installing application dependencies.
[builder] --------------------------------------------------------------------------------
[builder] Running "npm ci --quiet (NODE_ENV=production)"
[builder] 
[builder] added 115 packages, and audited 116 packages in 2s
[builder] 
[builder] 13 packages are looking for funding
[builder]   run `npm fund` for details
[builder] 
[builder] found 0 vulnerabilities
[builder] npm
[builder]  
[builder] notice
[builder]  
[builder] npm
[builder]  
[builder] notice
[builder]  New major version of npm available! 8.19.2 -> 10.5.0
[builder] npm
[builder]  
[builder] notice
[builder]  Changelog: <https://github.com/npm/cli/releases/tag/v10.5.0>
[builder] npm
[builder]  
[builder] notice
[builder]  Run `npm install -g npm@10.5.0` to update!
[builder] npm
[builder]  
[builder] notice
[builder]  
[builder] Done "npm ci --quiet (NODE_ENV=production)" (2.440139719s)
[builder] === Utils - Label Image (google.utils.label-image@0.0.2) ===
[builder] Timer: Builder ran for 6.205537844s and ended at 2024-03-01T07:20:33Z
===> EXPORTING
[exporter] Timer: Exporter started at 2024-03-01T07:20:34Z
[exporter] Adding layer 'google.nodejs.runtime:node'
[exporter] Adding layer 'google.nodejs.npm:env'
[exporter] Reusing layer 'buildpacksio/lifecycle:launch.sbom'
[exporter] Adding 1/1 app layer(s)
[exporter] Reusing layer 'buildpacksio/lifecycle:launcher'
[exporter] Adding layer 'buildpacksio/lifecycle:config'
[exporter] Reusing layer 'buildpacksio/lifecycle:process-types'
[exporter] Adding label 'io.buildpacks.lifecycle.metadata'
[exporter] Adding label 'io.buildpacks.build.metadata'
[exporter] Adding label 'io.buildpacks.project.metadata'
[exporter] Setting default process type 'web'
[exporter] Timer: Saving ghcr.io/hwakabh/6ow3idgirl:latest... started at 2024-03-01T07:20:35Z
[exporter] *** Images (3c771362b5e5):
[exporter]       ghcr.io/hwakabh/6ow3idgirl:latest
[exporter] Timer: Saving ghcr.io/hwakabh/6ow3idgirl:latest... ran for 1.730522705s and ended at 2024-03-01T07:20:37Z
[exporter] Timer: Exporter ran for 3.032458466s and ended at 2024-03-01T07:20:37Z
[exporter] Timer: Cache started at 2024-03-01T07:20:37Z
[exporter] Adding cache layer 'google.nodejs.runtime:node'
[exporter] Adding cache layer 'google.nodejs.npm:npm_modules'
[exporter] Timer: Cache ran for 225.542478ms and ended at 2024-03-01T07:20:37Z
Successfully built image ghcr.io/hwakabh/6ow3idgirl:latest

As fixed in 3908837, note that we could not include upper case in tag name with GHCR. Otherwise, the process will be exited error with following errors.

ERROR: failed to build: invalid image name 'ghcr.io/hwakabh/6ow3idGirl:latest': 'ghcr.io/hwakabh/6ow3idGirl:latest' is not a valid tag reference: could not parse reference: ghcr.io/hwakabh/6ow3idGirl:latest
Error: Process completed with exit code 1.
hwakabh commented 8 months ago

Confirmed that all workload has been deployed successfully with build image by GitHub Actions + Buildpacks, and we can see page rendered with temporary EXTERNAL-IP of Kubernetes service resource. Note that we had manually updated serviceType with kubectl edit after manifests applied, since we need to manage external access with Kubernetes ingress resources instead of service whose type is LoadBalancer.

Also, the strange thing is we can not reach to express app within container with default port tcp/3000, so we have updated it with tcp/8080 and mapped it with tcp/80 for external access.

% kubectl -n 6ow3idgirl get all
NAME                           READY   STATUS    RESTARTS   AGE
pod/express-555d69797d-btk2d   1/1     Running   0          4m22s
pod/express-555d69797d-mhcn7   1/1     Running   0          4m6s
pod/express-555d69797d-rkmnj   1/1     Running   0          4m17s

NAME              TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)        AGE
service/express   LoadBalancer   10.100.15.230   34.41.178.118   80:32389/TCP   6h26m

NAME                      READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/express   3/3     3            3           6h26m

NAME                                 DESIRED   CURRENT   READY   AGE
replicaset.apps/express-555d69797d   3         3         3       4m23s
replicaset.apps/express-5b579977b9   0         0         0       35m

% curl -D - -o /dev/null -s -X GET http://34.41.178.118
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 17396
ETag: W/"43f4-rnvat1TLASIZ3pj7i3KfZCFOXcA"
Date: Fri, 01 Mar 2024 13:22:09 GMT
Connection: keep-alive
Keep-Alive: timeout=5

% stern -n 6ow3idgirl express              
+ express-555d69797d-btk2d › express
+ express-555d69797d-mhcn7 › express
+ express-555d69797d-rkmnj › express
express-555d69797d-btk2d express 
express-555d69797d-btk2d express > low-mid-girl@0.0.0 start
express-555d69797d-btk2d express > node ./bin/www
express-555d69797d-btk2d express 
express-555d69797d-btk2d express Express app started with listening on 0.0.0.0:8080 ...
express-555d69797d-btk2d express (node:21) Warning: Accessing non-existent property 'route' of module exports inside circular dependency
express-555d69797d-btk2d express (Use `node --trace-warnings ...` to show where the warning was created)
express-555d69797d-btk2d express GET /stylesheets/prettyPhoto.css 200 206.389 ms - 19888
express-555d69797d-btk2d express GET /stylesheets/style.css 200 206.934 ms - 11145
express-555d69797d-btk2d express GET /javascripts/jquery.isotope.js 200 1.559 ms - 43251
express-555d69797d-btk2d express GET /javascripts/main.js 200 1.154 ms - 2040
express-555d69797d-btk2d express GET /images/section-bg.jpg 200 0.974 ms - 182969
express-555d69797d-btk2d express GET /images/portfolio/02-jacket.jpg 200 1.216 ms - 193132
express-555d69797d-btk2d express GET /images/portfolio/07-jacket.jpg 200 1.113 ms - 461390
express-555d69797d-btk2d express GET /images/portfolio/01-thumb.jpg 200 1.578 ms - 1126249
express-555d69797d-btk2d express GET /images/portfolio/06-thumb.jpg 200 1.420 ms - 1038559
express-555d69797d-btk2d express GET /images/portfolio/07-thumb.jpg 200 1.559 ms - 677145
express-555d69797d-btk2d express GET / 200 516.760 ms - 17396
express-555d69797d-mhcn7 express 
express-555d69797d-mhcn7 express > low-mid-girl@0.0.0 start
express-555d69797d-mhcn7 express > node ./bin/www
express-555d69797d-mhcn7 express 
express-555d69797d-mhcn7 express Express app started with listening on 0.0.0.0:8080 ...
express-555d69797d-mhcn7 express (node:21) Warning: Accessing non-existent property 'route' of module exports inside circular dependency
express-555d69797d-mhcn7 express (Use `node --trace-warnings ...` to show where the warning was created)
express-555d69797d-mhcn7 express GET / 200 432.770 ms - 17396
express-555d69797d-mhcn7 express GET /javascripts/jquery.1.11.1.js 200 3.488 ms - 95785
express-555d69797d-mhcn7 express GET /javascripts/SmoothScroll.js 200 1.599 ms - 13795
express-555d69797d-mhcn7 express GET /javascripts/waypoints.js 200 1.052 ms - 8044
express-555d69797d-mhcn7 express GET /javascripts/contact_me.js 200 1.133 ms - 2776
express-555d69797d-mhcn7 express GET /images/portfolio/03-jacket.jpg 200 0.897 ms - 218177
express-555d69797d-mhcn7 express GET /images/bg.jpg 200 1.136 ms - 1132187
express-555d69797d-mhcn7 express GET /images/portfolio/02-thumb.jpg 200 1.035 ms - 846603
express-555d69797d-mhcn7 express GET /images/portfolio/05-thumb.jpg 200 1.257 ms - 1767928
express-555d69797d-mhcn7 express GET /images/about.jpg 200 1.607 ms - 158650
express-555d69797d-mhcn7 express GET /images/apple-touch-icon.png 200 1.418 ms - 10473
express-555d69797d-rkmnj express 
express-555d69797d-rkmnj express > low-mid-girl@0.0.0 start
express-555d69797d-rkmnj express > node ./bin/www
express-555d69797d-rkmnj express 
express-555d69797d-rkmnj express Express app started with listening on 0.0.0.0:8080 ...
express-555d69797d-rkmnj express (node:21) Warning: Accessing non-existent property 'route' of module exports inside circular dependency
express-555d69797d-rkmnj express (Use `node --trace-warnings ...` to show where the warning was created)
express-555d69797d-rkmnj express GET / 200 2346.213 ms - 17396
express-555d69797d-rkmnj express GET /stylesheets/bootstrap.css 200 131.436 ms - 141591
express-555d69797d-rkmnj express GET /javascripts/bootstrap.js 200 18.229 ms - 67546
express-555d69797d-rkmnj express GET /javascripts/jquery.prettyPhoto.js 200 2.440 ms - 21514
express-555d69797d-rkmnj express GET /javascripts/jqBootstrapValidation.js 200 2.499 ms - 36171
express-555d69797d-rkmnj express GET /images/portfolio/01-jacket.jpg 200 2.913 ms - 198902
express-555d69797d-rkmnj express GET /images/portfolio/04-jacket.jpg 200 21.148 ms - 451220
express-555d69797d-rkmnj express GET /images/portfolio/05-jacket.jpg 200 2.580 ms - 55138
express-555d69797d-rkmnj express GET /images/portfolio/06-jacket.jpg 200 3.244 ms - 159348
express-555d69797d-rkmnj express GET /images/portfolio/03-thumb.jpg 200 17.112 ms - 1516894
express-555d69797d-rkmnj express GET /images/portfolio/04-thumb.jpg 200 61.982 ms - 1497659
express-555d69797d-rkmnj express GET /images/favicons.ico 200 15.517 ms - 2706
Screenshot 2024-03-01 at 22 24 14