From 99bc40bb7ab169ce72f542c6bcd4b92ef268e1b8 Mon Sep 17 00:00:00 2001 From: Miguel Molina Date: Tue, 19 Mar 2019 15:09:21 +0100 Subject: [PATCH] dockerfile: include zero-config mysql client Fixes #733 With this change, users won't even have to install the MySQL client on their machines or care about setting the parameters every single time they use it. By just `docker exec -it $IMAGE_NAME mysql` it will connect to gitbase without requiring any kind of configuration. Connection details are stored in `$HOME/.my.cnf`, which is generated at the start of the gitbase server. Because gitbase user and password can change when you run it, not only when you build the image, this needs to be done on startup. That's why `init.sh` has been included, which just creates the configuration for MySQL client and starts the gitbase server. Signed-off-by: Miguel Molina --- Dockerfile | 19 ++++++++++--------- init.sh | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 init.sh diff --git a/Dockerfile b/Dockerfile index 6099fa0e5..456d34680 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,11 +17,10 @@ RUN go build -ldflags="-X main.version=$(cat version.txt || echo "undefined") -X #================================= FROM alpine:3.8 +RUN apk add --no-cache mysql-client + RUN mkdir -p /opt/repos -ENV GITBASE_USER=root -ENV GITBASE_PASSWORD="" -ENV GITBASE_REPOS=/opt/repos EXPOSE 3306 ENV TINI_VERSION v0.18.0 @@ -29,12 +28,14 @@ ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-stati RUN chmod +x /tini ENTRYPOINT ["/tini", "--"] +ENV GITBASE_USER=root +ENV GITBASE_PASSWORD="" +ENV GITBASE_REPOS=/opt/repos +ENV MYSQL_HOST=127.0.0.1 + # copy build artifacts COPY --from=builder /bin/gitbase /bin/gitbase +ADD init.sh ./init.sh +RUN chmod +x ./init.sh -CMD /bin/gitbase server -v \ - --host=0.0.0.0 \ - --port=3306 \ - --user="$GITBASE_USER" \ - --password="$GITBASE_PASSWORD" \ - --directories="$GITBASE_REPOS" +ENTRYPOINT ["./init.sh"] diff --git a/init.sh b/init.sh new file mode 100644 index 000000000..54e0967fd --- /dev/null +++ b/init.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +cat <> "$HOME/.my.cnf" +[client] +user=${GITBASE_USER} +password=${GITBASE_PASSWORD} +EOT + +/tini -s -- /bin/gitbase server -v \ + --host=0.0.0.0 \ + --port=3306 \ + --user="$GITBASE_USER" \ + --password="$GITBASE_PASSWORD" \ + --directories="$GITBASE_REPOS" \ No newline at end of file