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

chore: add hono example #14

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Welcome to the Dockerfile Examples Repository! This repository is a comprehensiv
- [Angular](./angular/)
- [Next](./next)
- Nuxt
- [Hono](./hono)
- PHP
- Laravel
- Symfony
Expand Down
30 changes: 30 additions & 0 deletions hono/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# dev
.yarn/
!.yarn/releases
.vscode/*
!.vscode/launch.json
!.vscode/*.code-snippets
.idea/workspace.xml
.idea/usage.statistics.xml
.idea/shelf

# deps
node_modules/

# env
.env
.env.production

# logs
logs/
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

# misc
.DS_Store

dist/
31 changes: 31 additions & 0 deletions hono/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Documentation: https://hono.dev/docs/getting-started/nodejs#dockerfile

FROM node:lts-slim AS base

FROM base AS builder

WORKDIR /app

COPY package*json ./
RUN npm ci

COPY tsconfig.json src ./
RUN npm run build && \
npm prune --production

FROM base AS runner

WORKDIR /app

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

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 hono

EXPOSE 3000

CMD ["node", "/app/dist/index.js"]
42 changes: 42 additions & 0 deletions hono/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Hono Application Dockerfile Example

## Description

This repository provides a Dockerfile example for containerizing a Hono application. Hono is a web framework for the Edges (Cloudflare, Fastly, ...).

## Getting Started

1. Copy the `Dockerfile` and files used in the Dockerfile in your application
2. Build the Docker image by running the following command:

```bash
docker build -t image-name .
```

3. Once the image is built successfully, you can run a container using the following command:

```bash
docker run image-name
```

If the container needs specifying port and volumes if the container needed it.

4. Test your application container

## Customization

You can customize the Dockerfile example to fit your specific application needs. Here are a few areas you might consider modifying:

- **Dependencies**: If your application requires additional dependencies, you can use the RUN command in the Dockerfile to install them. Make sure to update the appropriate package manager command based on your application setup.
- **Environment Variables**: If your application requires environment variables, you can pass them to the container using the -e flag when running the docker run command.
- **Volumes**: If your application needs to access files or directories outside the container, you can use volume mounts to provide access. Update the VOLUME instruction in the Dockerfile and use the -v flag when running the docker run command.

## Contributing

Contributions to this Dockerfile example are welcome! If you have any improvements or suggestions, feel free to submit a pull request.

Please ensure that your changes align with the best practices and conventions outlined in the Docker and language/framework documentation.

## Disclaimer

The Dockerfile example provided in this repository is for educational and reference purposes. It is important to review and adapt it to meet the specific security and performance requirements of your case before using it in a production environment.
161 changes: 161 additions & 0 deletions hono/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions hono/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "hono",
"type": "module",
"scripts": {
"dev": "tsx watch src/index.ts",
"build": "tsc"
},
"dependencies": {
"@hono/node-server": "^1.12.2",
"hono": "^4.6.1"
},
"devDependencies": {
"@types/node": "^20.11.17",
"tsx": "^4.7.1",
"typescript": "^5.6.2"
}
}
16 changes: 16 additions & 0 deletions hono/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { serve } from '@hono/node-server'
import { Hono } from 'hono'

const app = new Hono()

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

const port = 3000
console.log(`Server is running on port ${port}`)

serve({
fetch: app.fetch,
port
})
19 changes: 19 additions & 0 deletions hono/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"outDir": "./dist",
"strict": true,
"skipLibCheck": true,
"types": [
"node"
],
"jsx": "react-jsx",
"jsxImportSource": "hono/jsx",
},
"exclude": [
"node_modules",
"dist"
]
}