Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web): dockerize web application #1253

Merged
merged 5 commits into from
Oct 9, 2024
Merged

feat(web): dockerize web application #1253

merged 5 commits into from
Oct 9, 2024

Conversation

KeisukeYamashita
Copy link
Contributor

@KeisukeYamashita KeisukeYamashita commented Oct 8, 2024

Overview

I've Dockerized the web application to be portable and deployable to container runtimes (e.g. Cloud Run, Kubernetes). We aim to host the web on Cloud Run.

What I've done

I've containerised the application and implemented the deployment workflow.

What I haven't done

I haven't decommissioned our GCS stuff yet.
I've implemented it separately from the existing system so that we can deploy, test, and switch over without any impact.

How I tested

I've built in manually:

$ docker build . -t reearth-cms-web && docker run -e AUTH0_AUDIENCE="https://api.cms.dev.reearth.io" -e AUTH0_CLIENT_ID="xxx" -e AUTH0_DOMAIN="https://reearth-dev.auth0.com" -p 8080:8080 reearth-cms-web

Then, I accessed some of the paths and looks okay:

$ curl http://localhost:8080/assets/abap-Eabmoog9.js
$ curl http://localhost:8080/reearth_config.json
$ curl http://localhost:8080

All returned the contents under //usr/share/nginx/html based on the request path.

Screenshot

Which point I want you to review particularly

Memo

Note that I haven't added any cache configurations yet, perf tuning will be another PR.

Copy link

netlify bot commented Oct 8, 2024

Deploy Preview for reearth-cms ready!

Name Link
🔨 Latest commit d686996
🔍 Latest deploy log https://app.netlify.com/sites/reearth-cms/deploys/6705ae5d7cd4e900083f9b34
😎 Deploy Preview https://deploy-preview-1253--reearth-cms.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.


jobs:
deploy_web:
# TODO: Remove after dockerizing the web.
deploy_web_gcs:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

I changed it so that I could remove this block entirely after verifying our new Docker image without renaming the web (Docker) job.

@@ -15,13 +15,6 @@ import { configDefaults } from "vitest/config";

import pkg from "./package.json";

let commitHash = "";
try {
commitHash = execSync("git rev-parse HEAD").toString().trimEnd();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Because we built in Docker, it has no Git information.

Copy link

netlify bot commented Oct 8, 2024

Deploy Preview for reearth-cms ready!

Name Link
🔨 Latest commit 692d31f
🔍 Latest deploy log https://app.netlify.com/sites/reearth-cms/deploys/67065e3ecf16df000932ec4d
😎 Deploy Preview https://deploy-preview-1253--reearth-cms.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@KeisukeYamashita KeisukeYamashita force-pushed the dockerize-web branch 4 times, most recently from b81e328 to d98eddd Compare October 8, 2024 22:33
@@ -0,0 +1,11 @@
*
Copy link
Contributor Author

@KeisukeYamashita KeisukeYamashita Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Allow listing is always good and safe.

Comment on lines +29 to +35
# Default to Cloud Run port.
# Ref: https://cloud.google.com/run/docs/reference/container-contract#port
ENV PORT=8080

# Defaults Google Cloud Load Balancer header.
# Ref: https://cloud.google.com/load-balancing/docs/https#target-proxies
ENV REAL_IP_HEADER=X-Forwarded-For
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

IMHO, vendor-specific configurations should be configurable since we are an OSS product; in this case, we can pass -e to override on execution.

Comment on lines +1 to +15
log_format json escape=json '{'
'"body_bytes_sent": "$body_bytes_sent",'
'"http_referer": "$http_referer",'
'"http_user_agent": "$http_user_agent",'
'"remote_ip": "$remote_addr",'
'"remote_user": "$remote_user",'
'"request": "$request",'
'"request_id": "$request_id",'
'"request_method": "$request_method",'
'"request_time": "$request_time",'
'"request_uri": "$request_uri",'
'"server_name": "$server_name",'
'"status": "$status",'
'"time": "$time_iso8601"'
'}';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I accessed the container via curl and it will be like this:

{"body_bytes_sent": "739","http_referer": "","http_user_agent": "curl/8.7.1","remote_ip": "xxx.xxx.xxx.xxx","remote_user": "","request": "GET / HTTP/1.1","request_id": "fde3377155ab9765825dff57cb2a83f6","request_method": "GET","request_time": "0.000","request_uri": "/","server_name": "_","status": "200","time": "2024-10-08T22:48:41+00:00"}

@KeisukeYamashita KeisukeYamashita marked this pull request as ready for review October 8, 2024 22:53
@rot1024 rot1024 changed the title feat(web): dockerize application feat(web): dockerize web application Oct 9, 2024
web/vite.config.ts Outdated Show resolved Hide resolved

- uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Workload Identity is not used... Later we want to change

@KeisukeYamashita KeisukeYamashita merged commit 4e7f550 into main Oct 9, 2024
8 checks passed
@KeisukeYamashita KeisukeYamashita deleted the dockerize-web branch October 9, 2024 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants