diff --git a/README.md b/README.md index 5e6d757..f640bb8 100644 --- a/README.md +++ b/README.md @@ -47,10 +47,10 @@ Generates the endpoints (or a whole app) from a mapping (SQL query -> URL) 1. Generate code | Language | Command for code generation | Example of generated files | Libraries | | -----------| ----------------------------| ---------------------------| --------- | - | JavaScript | `npx query2app --lang js` | [`app.js`](examples/js/express/mysql/app.js)
[`routes.js`](examples/js/express/mysql/routes.js)
[`package.json`](examples/js/express/mysql/package.json) | Web: [`express`](https://www.npmjs.com/package/express)
Database: [`mysql`](https://www.npmjs.com/package/mysql) | - | TypeScript | `npx query2app --lang ts` | [`app.ts`](examples/ts/express/mysql/app.ts)
[`routes.ts`](examples/ts/express/mysql/routes.ts)
[`package.json`](examples/ts/express/mysql/package.json)
[`tsconfig.json`](examples/ts/express/mysql/tsconfig.json) | Web: [`express`](https://www.npmjs.com/package/express)
Database: [`mysql`](https://www.npmjs.com/package/mysql) | + | JavaScript | `npx query2app --lang js` | [`app.js`](examples/js/express/mysql/app.js)
[`routes.js`](examples/js/express/mysql/routes.js)
[`package.json`](examples/js/express/mysql/package.json)
[`Dockerfile`](examples/js/express/mysql/Dockerfile) | Web: [`express`](https://www.npmjs.com/package/express)
Database: [`mysql`](https://www.npmjs.com/package/mysql) | + | TypeScript | `npx query2app --lang ts` | [`app.ts`](examples/ts/express/mysql/app.ts)
[`routes.ts`](examples/ts/express/mysql/routes.ts)
[`package.json`](examples/ts/express/mysql/package.json)
[`tsconfig.json`](examples/ts/express/mysql/tsconfig.json)
[`Dockerfile`](examples/ts/express/mysql/Dockerfile) | Web: [`express`](https://www.npmjs.com/package/express)
Database: [`mysql`](https://www.npmjs.com/package/mysql) | | Golang | `npx query2app --lang go` | [`app.go`](examples/go/chi/mysql/app.go)
[`routes.go`](examples/go/chi/mysql/routes.go)
[`go.mod`](examples/go/chi/mysql/go.mod) | Web: [`go-chi/chi`](https://github.com/go-chi/chi)
Database: [`go-sql-driver/mysql`](https://github.com/go-sql-driver/mysql), [`jmoiron/sqlx`](https://github.com/jmoiron/sqlx) | - | Python | `npx query2app --lang python` | [`app.py`](examples/python/fastapi/postgres/app.py)
[`db.py`](examples/python/fastapi/postgres/db.py)
[`routes.py`](examples/python/fastapi/postgres/routes.py)
[`requirements.txt`](examples/python/fastapi/postgres/requirements.txt) | Web: [FastAPI](https://github.com/tiangolo/fastapi), [Uvicorn](https://www.uvicorn.org)
Database: [psycopg2](https://pypi.org/project/psycopg2/) | + | Python | `npx query2app --lang python` | [`app.py`](examples/python/fastapi/postgres/app.py)
[`db.py`](examples/python/fastapi/postgres/db.py)
[`routes.py`](examples/python/fastapi/postgres/routes.py)
[`requirements.txt`](examples/python/fastapi/postgres/requirements.txt)
[`Dockerfile`](examples/python/fastapi/postgres/Dockerfile) | Web: [FastAPI](https://github.com/tiangolo/fastapi), [Uvicorn](https://www.uvicorn.org)
Database: [psycopg2](https://pypi.org/project/psycopg2/) | 1. Run the application | Language | Commands to run the application | diff --git a/examples/js/express/mysql/Dockerfile b/examples/js/express/mysql/Dockerfile new file mode 100644 index 0000000..efc57fe --- /dev/null +++ b/examples/js/express/mysql/Dockerfile @@ -0,0 +1,8 @@ +FROM node:18-bookworm +WORKDIR /opt/app +COPY package.json ./ +ENV NPM_CONFIG_UPDATE_NOTIFIER=false +RUN npm install --no-audit --no-fund +COPY *.js ./ +USER node +CMD [ "npm", "start" ] diff --git a/examples/python/fastapi/postgres/Dockerfile b/examples/python/fastapi/postgres/Dockerfile new file mode 100644 index 0000000..312f62b --- /dev/null +++ b/examples/python/fastapi/postgres/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.7-bookworm +WORKDIR /opt/app +COPY requirements.txt ./ +RUN pip install --no-cache-dir --upgrade -r requirements.txt +COPY *.py ./ +CMD [ "uvicorn", "app:app", "--host", "0.0.0.0" ] diff --git a/examples/ts/express/mysql/Dockerfile b/examples/ts/express/mysql/Dockerfile new file mode 100644 index 0000000..82b761d --- /dev/null +++ b/examples/ts/express/mysql/Dockerfile @@ -0,0 +1,9 @@ +FROM node:18-bookworm +WORKDIR /opt/app +COPY package.json ./ +ENV NPM_CONFIG_UPDATE_NOTIFIER=false +RUN npm install --no-audit --no-fund +COPY tsconfig.json *.ts ./ +RUN npm run build +USER node +CMD [ "npm", "start" ] diff --git a/src/cli.js b/src/cli.js index a4eba52..424352b 100755 --- a/src/cli.js +++ b/src/cli.js @@ -321,6 +321,18 @@ const createDependenciesDescriptor = async (destDir, { lang }) => { return fsPromises.writeFile(resultFile, minimalPackageJson) } +const createDockerfile = async (destDir, lang) => { + if (lang == 'go') { + return + } + const fileName = 'Dockerfile' + console.log('Generate', fileName) + + const resultFile = path.join(destDir, fileName) + + return fsPromises.copyFile(`${__dirname}/templates/${fileName}.${lang}`, resultFile) +} + const createTypeScriptConfig = async (destDir, lang) => { if (lang !== 'ts') { return @@ -361,6 +373,7 @@ const main = async (argv) => { await createEndpoints(destDir, argv, config) await createDependenciesDescriptor(destDir, argv) await createTypeScriptConfig(destDir, argv.lang) + await createDockerfile(destDir, lang) console.info('The application has been generated!') console.info(generator.usageExampleAsText()) diff --git a/src/templates/Dockerfile.js b/src/templates/Dockerfile.js new file mode 100644 index 0000000..efc57fe --- /dev/null +++ b/src/templates/Dockerfile.js @@ -0,0 +1,8 @@ +FROM node:18-bookworm +WORKDIR /opt/app +COPY package.json ./ +ENV NPM_CONFIG_UPDATE_NOTIFIER=false +RUN npm install --no-audit --no-fund +COPY *.js ./ +USER node +CMD [ "npm", "start" ] diff --git a/src/templates/Dockerfile.py b/src/templates/Dockerfile.py new file mode 100644 index 0000000..312f62b --- /dev/null +++ b/src/templates/Dockerfile.py @@ -0,0 +1,6 @@ +FROM python:3.7-bookworm +WORKDIR /opt/app +COPY requirements.txt ./ +RUN pip install --no-cache-dir --upgrade -r requirements.txt +COPY *.py ./ +CMD [ "uvicorn", "app:app", "--host", "0.0.0.0" ] diff --git a/src/templates/Dockerfile.ts b/src/templates/Dockerfile.ts new file mode 100644 index 0000000..82b761d --- /dev/null +++ b/src/templates/Dockerfile.ts @@ -0,0 +1,9 @@ +FROM node:18-bookworm +WORKDIR /opt/app +COPY package.json ./ +ENV NPM_CONFIG_UPDATE_NOTIFIER=false +RUN npm install --no-audit --no-fund +COPY tsconfig.json *.ts ./ +RUN npm run build +USER node +CMD [ "npm", "start" ]