Skip to content

Commit 7132da6

Browse files
committed
feat: generate Dockerfile for Golang app
Part of #42
1 parent 00a1f9d commit 7132da6

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Generates the endpoints (or a whole app) from a mapping (SQL query -> URL)
4949
| -----------| ----------------------------| ---------------------------| --------- |
5050
| JavaScript | `npx query2app --lang js` | [`app.js`](examples/js/express/mysql/app.js)<br/>[`routes.js`](examples/js/express/mysql/routes.js)<br/>[`package.json`](examples/js/express/mysql/package.json)<br/>[`Dockerfile`](examples/js/express/mysql/Dockerfile) | Web: [`express`](https://www.npmjs.com/package/express)<br>Database: [`mysql`](https://www.npmjs.com/package/mysql) |
5151
| TypeScript | `npx query2app --lang ts` | [`app.ts`](examples/ts/express/mysql/app.ts)<br/>[`routes.ts`](examples/ts/express/mysql/routes.ts)<br/>[`package.json`](examples/ts/express/mysql/package.json)<br/>[`tsconfig.json`](examples/ts/express/mysql/tsconfig.json)<br/>[`Dockerfile`](examples/ts/express/mysql/Dockerfile) | Web: [`express`](https://www.npmjs.com/package/express)<br>Database: [`mysql`](https://www.npmjs.com/package/mysql) |
52-
| Golang | `npx query2app --lang go` | [`app.go`](examples/go/chi/mysql/app.go)<br/>[`routes.go`](examples/go/chi/mysql/routes.go)<br/>[`go.mod`](examples/go/chi/mysql/go.mod) | Web: [`go-chi/chi`](https://github.com/go-chi/chi)<br/>Database: [`go-sql-driver/mysql`](https://github.com/go-sql-driver/mysql), [`jmoiron/sqlx`](https://github.com/jmoiron/sqlx) |
52+
| Golang | `npx query2app --lang go` | [`app.go`](examples/go/chi/mysql/app.go)<br/>[`routes.go`](examples/go/chi/mysql/routes.go)<br/>[`go.mod`](examples/go/chi/mysql/go.mod)<br/>[`Dockerfile`](examples/go/chi/mysql/Dockerfile) | Web: [`go-chi/chi`](https://github.com/go-chi/chi)<br/>Database: [`go-sql-driver/mysql`](https://github.com/go-sql-driver/mysql), [`jmoiron/sqlx`](https://github.com/jmoiron/sqlx) |
5353
| Python | `npx query2app --lang python` | [`app.py`](examples/python/fastapi/postgres/app.py)<br/>[`db.py`](examples/python/fastapi/postgres/db.py)<br/>[`routes.py`](examples/python/fastapi/postgres/routes.py)<br/>[`requirements.txt`](examples/python/fastapi/postgres/requirements.txt)<br/>[`Dockerfile`](examples/python/fastapi/postgres/Dockerfile) | Web: [FastAPI](https://github.com/tiangolo/fastapi), [Uvicorn](https://www.uvicorn.org)<br/>Database: [psycopg2](https://pypi.org/project/psycopg2/) |
5454

5555
1. Run the application

examples/go/chi/mysql/Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM golang:1.14 AS builder
2+
WORKDIR /opt
3+
COPY go.mod ./
4+
RUN go mod download
5+
COPY *.go ./
6+
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o app
7+
8+
FROM scratch
9+
WORKDIR /opt/app
10+
COPY --from=builder /opt/app .
11+
CMD [ "/opt/app/app" ]

src/cli.js

-3
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,6 @@ const createDependenciesDescriptor = async (destDir, { lang }) => {
322322
}
323323

324324
const createDockerfile = async (destDir, lang) => {
325-
if (lang == 'go') {
326-
return
327-
}
328325
const fileName = 'Dockerfile'
329326
console.log('Generate', fileName)
330327

src/templates/Dockerfile.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM golang:1.14 AS builder
2+
WORKDIR /opt
3+
COPY go.mod ./
4+
RUN go mod download
5+
COPY *.go ./
6+
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o app
7+
8+
FROM scratch
9+
WORKDIR /opt/app
10+
COPY --from=builder /opt/app .
11+
CMD [ "/opt/app/app" ]

0 commit comments

Comments
 (0)