diff --git a/README.md b/README.md index 29b54a3..67747b7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/hono/.gitignore b/hono/.gitignore new file mode 100644 index 0000000..7eb803e --- /dev/null +++ b/hono/.gitignore @@ -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/ diff --git a/hono/Dockerfile b/hono/Dockerfile new file mode 100644 index 0000000..ec1d1fb --- /dev/null +++ b/hono/Dockerfile @@ -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"] diff --git a/hono/README.md b/hono/README.md new file mode 100644 index 0000000..71646f9 --- /dev/null +++ b/hono/README.md @@ -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. diff --git a/hono/package-lock.json b/hono/package-lock.json new file mode 100644 index 0000000..5332a0a --- /dev/null +++ b/hono/package-lock.json @@ -0,0 +1,161 @@ +{ + "name": "hono", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "hono", + "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" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.23.1.tgz", + "integrity": "sha512-EV6+ovTsEXCPAp58g2dD68LxoP/wK5pRvgy0J/HxPGB009omFPv3Yet0HiaqvrIrgPTBuC6wCH1LTOY91EO5hQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@hono/node-server": { + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@hono/node-server/-/node-server-1.12.2.tgz", + "integrity": "sha512-xjzhqhSWUE/OhN0g3KCNVzNsQMlFUAL+/8GgPUr3TKcU7cvgZVBGswFofJ8WwGEHTqobzze1lDpGJl9ZNckDhA==", + "engines": { + "node": ">=18.14.1" + }, + "peerDependencies": { + "hono": "^4" + } + }, + "node_modules/@types/node": { + "version": "20.16.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.16.5.tgz", + "integrity": "sha512-VwYCweNo3ERajwy0IUlqqcyZ8/A7Zwa9ZP3MnENWcB11AejO+tLy3pu850goUW2FC/IJMdZUfKpX/yxL1gymCA==", + "dev": true, + "dependencies": { + "undici-types": "~6.19.2" + } + }, + "node_modules/esbuild": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.23.1.tgz", + "integrity": "sha512-VVNz/9Sa0bs5SELtn3f7qhJCDPCF5oMEl5cO9/SSinpE9hbPVvxbd572HH5AKiP7WD8INO53GgfDDhRjkylHEg==", + "dev": true, + "hasInstallScript": true, + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.23.1", + "@esbuild/android-arm": "0.23.1", + "@esbuild/android-arm64": "0.23.1", + "@esbuild/android-x64": "0.23.1", + "@esbuild/darwin-arm64": "0.23.1", + "@esbuild/darwin-x64": "0.23.1", + "@esbuild/freebsd-arm64": "0.23.1", + "@esbuild/freebsd-x64": "0.23.1", + "@esbuild/linux-arm": "0.23.1", + "@esbuild/linux-arm64": "0.23.1", + "@esbuild/linux-ia32": "0.23.1", + "@esbuild/linux-loong64": "0.23.1", + "@esbuild/linux-mips64el": "0.23.1", + "@esbuild/linux-ppc64": "0.23.1", + "@esbuild/linux-riscv64": "0.23.1", + "@esbuild/linux-s390x": "0.23.1", + "@esbuild/linux-x64": "0.23.1", + "@esbuild/netbsd-x64": "0.23.1", + "@esbuild/openbsd-arm64": "0.23.1", + "@esbuild/openbsd-x64": "0.23.1", + "@esbuild/sunos-x64": "0.23.1", + "@esbuild/win32-arm64": "0.23.1", + "@esbuild/win32-ia32": "0.23.1", + "@esbuild/win32-x64": "0.23.1" + } + }, + "node_modules/get-tsconfig": { + "version": "4.8.1", + "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.8.1.tgz", + "integrity": "sha512-k9PN+cFBmaLWtVz29SkUoqU5O0slLuHJXt/2P+tMVFT+phsSGXGkp9t3rQIqdz0e+06EHNGs3oM6ZX1s2zHxRg==", + "dev": true, + "dependencies": { + "resolve-pkg-maps": "^1.0.0" + }, + "funding": { + "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" + } + }, + "node_modules/hono": { + "version": "4.6.1", + "resolved": "https://registry.npmjs.org/hono/-/hono-4.6.1.tgz", + "integrity": "sha512-6NGwvttY1+HAFii08VYiEKI6ETPAFbpLntpm2M/MogEsAFWdZV74UNT+2M4bmqX90cIQhjlpBSP+tO+CfB0uww==", + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/resolve-pkg-maps": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", + "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", + "dev": true, + "funding": { + "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" + } + }, + "node_modules/tsx": { + "version": "4.19.1", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.19.1.tgz", + "integrity": "sha512-0flMz1lh74BR4wOvBjuh9olbnwqCPc35OOlfyzHba0Dc+QNUeWX/Gq2YTbnwcWPO3BMd8fkzRVrHcsR+a7z7rA==", + "dev": true, + "dependencies": { + "esbuild": "~0.23.0", + "get-tsconfig": "^4.7.5" + }, + "bin": { + "tsx": "dist/cli.mjs" + }, + "engines": { + "node": ">=18.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + } + }, + "node_modules/typescript": { + "version": "5.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz", + "integrity": "sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "6.19.8", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", + "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", + "dev": true + } + } +} diff --git a/hono/package.json b/hono/package.json new file mode 100644 index 0000000..6490510 --- /dev/null +++ b/hono/package.json @@ -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" + } +} diff --git a/hono/src/index.ts b/hono/src/index.ts new file mode 100644 index 0000000..f39af17 --- /dev/null +++ b/hono/src/index.ts @@ -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 +}) diff --git a/hono/tsconfig.json b/hono/tsconfig.json new file mode 100644 index 0000000..e16e914 --- /dev/null +++ b/hono/tsconfig.json @@ -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" + ] +} \ No newline at end of file