Skip to content

Commit

Permalink
dockerfile: include zero-config mysql client
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
erizocosmico committed Mar 19, 2019
1 parent d9ce6c7 commit 99bc40b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
19 changes: 10 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,25 @@ 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
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-static-amd64 /tini
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"]
14 changes: 14 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

cat <<EOT >> "$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"

0 comments on commit 99bc40b

Please sign in to comment.