Skip to content

Commit

Permalink
feat: add health check (#11)
Browse files Browse the repository at this point in the history
* feat: add health check

* chore: fix

* fix: docker file

* fix: dockerfile

* fix: directory

* fix: docker file

* fix: settings

* fix: setting

* fix: setting

* fix: setting

* fix: settings

* fix: remove no traffic

* fix: build yaml

* fix: port env

* fix: name
  • Loading branch information
yamashita-kenngo authored May 3, 2024
1 parent a2933a9 commit 92d3733
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 122 deletions.
3 changes: 3 additions & 0 deletions .gcloudignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.gcloudignore
.git
.gitignore
18 changes: 9 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ FROM node:22-alpine AS base
FROM base AS builder

RUN apk add --no-cache libc6-compat
WORKDIR /backend
WORKDIR /app

COPY package*.json tsconfig.json src ./
COPY package*json tsconfig.json src ./

RUN npm ci && \
npm run build && \
npm prune --production

FROM base AS runner
WORKDIR /backend
WORKDIR /app

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 autonomy
RUN adduser --system --uid 1001 hono

COPY --from=builder --chown=autonomy:nodejs /backend/node_modules /backend/node_modules
COPY --from=builder --chown=autonomy:nodejs /backend/dist /backend/dist
COPY --from=builder --chown=autonomy:nodejs /backend/package.json /backend/package.json
COPY --from=builder --chown=hono:nodejs /app/node_modules /app/node_modules
COPY --from=builder --chown=hono:nodejs /app/dist /app/dist
COPY --from=builder --chown=hono:nodejs /app/package.json /app/package.json

USER autonomy
USER hono
EXPOSE 3000

CMD ["node", "/backend/dist/index.js"]
CMD ["node", "/app/dist/index.js"]
1 change: 0 additions & 1 deletion backend/.gitignore

This file was deleted.

8 changes: 0 additions & 8 deletions backend/README.md

This file was deleted.

62 changes: 15 additions & 47 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ steps:
- '--no-cache'
- '-t'
- >-
$_AR_HOSTNAME/$PROJECT_ID/cloud-run-source-deploy/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA
$_AR_HOSTNAME/$PROJECT_ID/autonomy/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA
- .
- '-f'
- Dockerfile
Expand All @@ -14,68 +14,36 @@ steps:
args:
- push
- >-
$_AR_HOSTNAME/$PROJECT_ID/cloud-run-source-deploy/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA
$_AR_HOSTNAME/$PROJECT_ID/autonomy/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA
id: Push
# - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:slim'
# args:
# - run
# - services
# - update
# - $_SERVICE_NAME
# - '--platform=managed'
# - >-
# --image=$_AR_HOSTNAME/$PROJECT_ID/cloud-run-source-deploy/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA
# - >-
# --labels=managed-by=gcp-cloud-build-deploy-cloud-run,commit-sha=$COMMIT_SHA,gcb-build-id=$BUILD_ID,gcb-trigger-id=$_TRIGGER_ID
# - '--region=$_DEPLOY_REGION'
# - '--quiet'
# id: Deploy
# entrypoint: gcloud
# - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:slim'
# args:
# - run
# - services
# - update-traffic
# - $_SERVICE_NAME
# - '--platform=managed'
# - '--region=$_DEPLOY_REGION'
# - '--to-latest'
# - '--quiet'
# id: UpdateTraffic
# entrypoint: gcloud
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:slim'
args:
- run
- deploy
- apply
- '--region=$_DEPLOY_REGION'
- '--file=deploy/clouddeploy.yaml'
id: ApplyCloudDeployDeliveryPipeline
entrypoint: gcloud
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk:slim'
args:
- deploy
- releases
- create
- release-$SHORT_SHA
- $_SERVICE_NAME
- '--platform=managed'
- >-
--image=$_AR_HOSTNAME/$PROJECT_ID/autonomy/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA
- >-
--labels=managed-by=gcp-cloud-build-deploy-cloud-run,commit-sha=$COMMIT_SHA,gcb-build-id=$BUILD_ID,gcb-trigger-id=$_TRIGGER_ID
- '--region=$_DEPLOY_REGION'
- '--delivery-pipeline=demo-backend-api'
- '--skaffold-file=deploy/skaffold.yaml'
- >-
--images=demo-backend-api=$_AR_HOSTNAME/$PROJECT_ID/cloud-run-source-deploy/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA
id: CreateCloudDeployRelease
--tag=$BRANCH_NAME
- '--quiet'
id: DeployTag
entrypoint: gcloud
images:
- >-
$_AR_HOSTNAME/$PROJECT_ID/cloud-run-source-deploy/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA
$_AR_HOSTNAME/$PROJECT_ID/autonomy/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA
options:
substitutionOption: ALLOW_LOOSE
substitutions:
_PLATFORM: managed
_SERVICE_NAME: demo-backend-api
_SERVICE_NAME: backend-accounts-api
_TRIGGER_ID: 5769c5a8-3db3-4015-a4d1-0e1d21ba0561
_DEPLOY_REGION: asia-northeast1
_AR_HOSTNAME: asia-northeast1-docker.pkg.dev
tags:
- gcp-cloud-build-deploy-cloud-run
- gcp-cloud-build-deploy-cloud-run-managed
- demo-backend-api
- backend-accounts-api
51 changes: 0 additions & 51 deletions cloudbuild_pr.yaml

This file was deleted.

File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions backend/package.json → package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"scripts": {
"dev": "tsx watch src/index.ts",
"test": "jest --verbose --forceExit"
"test": "jest --verbose --forceExit",
"build": "tsc"
},
"dependencies": {
"@hono/node-server": "^1.11.1",
Expand All @@ -16,5 +17,6 @@
},
"volta": {
"node": "22.1.0"
}
},
"type": "module"
}
File renamed without changes.
4 changes: 2 additions & 2 deletions backend/src/index.ts → src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { Hono } from 'hono'
const app = new Hono()

app.get('/', (c) => {
return c.text('Hello Hono!')
return c.json({ message: 'Hello World!'})
})

const port = 3000
const port = parseInt(process.env.PORT!) || 3000
console.log(`Server is running on port ${port}`)

serve({
Expand Down
8 changes: 6 additions & 2 deletions backend/tsconfig.json → tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
],
"jsx": "react-jsx",
"jsxImportSource": "hono/jsx",
"allowJs": true
}
"allowJs": true,
"outDir": "./dist"
},
"exclude": [
"node_modules",
"dist"]
}

0 comments on commit 92d3733

Please sign in to comment.