Skip to content

Commit

Permalink
feat: generate Dockerfile for Golang app
Browse files Browse the repository at this point in the history
Part of #42
  • Loading branch information
php-coder committed Mar 15, 2024
1 parent 00a1f9d commit 7132da6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Generates the endpoints (or a whole app) from a mapping (SQL query -> URL)
| -----------| ----------------------------| ---------------------------| --------- |
| 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) |
| 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) |
| 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) |
| 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) |
| 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/) |

1. Run the application
Expand Down
11 changes: 11 additions & 0 deletions examples/go/chi/mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.14 AS builder
WORKDIR /opt
COPY go.mod ./
RUN go mod download
COPY *.go ./
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o app

FROM scratch
WORKDIR /opt/app
COPY --from=builder /opt/app .
CMD [ "/opt/app/app" ]
3 changes: 0 additions & 3 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,6 @@ const createDependenciesDescriptor = async (destDir, { lang }) => {
}

const createDockerfile = async (destDir, lang) => {
if (lang == 'go') {
return
}
const fileName = 'Dockerfile'
console.log('Generate', fileName)

Expand Down
11 changes: 11 additions & 0 deletions src/templates/Dockerfile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.14 AS builder
WORKDIR /opt
COPY go.mod ./
RUN go mod download
COPY *.go ./
RUN CGO_ENABLED=0 go build -ldflags="-s -w" -o app

FROM scratch
WORKDIR /opt/app
COPY --from=builder /opt/app .
CMD [ "/opt/app/app" ]

0 comments on commit 7132da6

Please sign in to comment.