sqler sql 转rest api 的docker image

时间:2021-12-12 17:57:32

最新sqler 又发布了一个版本,同时官方文档也更新,对于数据库的连接有了详细的说明

Dockerfile

为了方便以及减少大小,使用多阶段构建,同时都通过环境变量运行

FROM alpine:latest as build
ENV VERSION=v1.6
WORKDIR /app
RUN apk update && apk add wget unzip
RUN wget https://github.com/alash3al/sqler/releases/download/${VERSION}/sqler_linux_amd64.zip
RUN unzip sqler_linux_amd64.zip && chmod +x sqler_linux_amd64
FROM alpine:latest
ENV APPVERSION=1.6
LABEL VERSION="sqler-${APPVERSION}"
LABEL EMAIL="1141519465@qq.com"
LABEL AUTHOR="dalongrong"
WORKDIR /app
ENV DSN="root:root@tcp(127.0.0.1:3306)/test?multiStatements=true"
ENV RESP=:3678
ENV CONFIG=config.example.hcl
ENV REST=:8025
ENV DRIVER=mysql
ENV WORKERS=4
EXPOSE 3678 8025
ENV PATH=$PATH:/usr/local/bin
COPY config/config.example.hcl /app/config.example.hcl
COPY entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh
COPY --from=build /app/sqler_linux_amd64 /usr/local/bin/sqler
ENTRYPOINT ["./entrypoint.sh"]
 

entrypoint.sh

实际上就是运行的时候使用配置参数,镜像添加了默认参数,参考env

#!/bin/sh
sqler -driver ${DRIVER} -rest ${REST} -dsn ${DSN} -config ${CONFIG} -workers ${WORKERS} -resp ${RESP}

构建

docker build -t dalongrong/sqler:1.6

说明

构建的镜像已经push dockerhub 了

参考资料

https://github.com/rongfengliang/sqler-docker-compose
https://github.com/alash3al/sqler
https://cloud.docker.com/u/dalongrong/repository/docker/dalongrong/sqler