Skip to content

Commit 99bc40b

Browse files
committed
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 <[email protected]>
1 parent d9ce6c7 commit 99bc40b

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

Dockerfile

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,25 @@ RUN go build -ldflags="-X main.version=$(cat version.txt || echo "undefined") -X
1717
#=================================
1818
FROM alpine:3.8
1919

20+
RUN apk add --no-cache mysql-client
21+
2022
RUN mkdir -p /opt/repos
2123

22-
ENV GITBASE_USER=root
23-
ENV GITBASE_PASSWORD=""
24-
ENV GITBASE_REPOS=/opt/repos
2524
EXPOSE 3306
2625

2726
ENV TINI_VERSION v0.18.0
2827
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-static-amd64 /tini
2928
RUN chmod +x /tini
3029
ENTRYPOINT ["/tini", "--"]
3130

31+
ENV GITBASE_USER=root
32+
ENV GITBASE_PASSWORD=""
33+
ENV GITBASE_REPOS=/opt/repos
34+
ENV MYSQL_HOST=127.0.0.1
35+
3236
# copy build artifacts
3337
COPY --from=builder /bin/gitbase /bin/gitbase
38+
ADD init.sh ./init.sh
39+
RUN chmod +x ./init.sh
3440

35-
CMD /bin/gitbase server -v \
36-
--host=0.0.0.0 \
37-
--port=3306 \
38-
--user="$GITBASE_USER" \
39-
--password="$GITBASE_PASSWORD" \
40-
--directories="$GITBASE_REPOS"
41+
ENTRYPOINT ["./init.sh"]

init.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
cat <<EOT >> "$HOME/.my.cnf"
4+
[client]
5+
user=${GITBASE_USER}
6+
password=${GITBASE_PASSWORD}
7+
EOT
8+
9+
/tini -s -- /bin/gitbase server -v \
10+
--host=0.0.0.0 \
11+
--port=3306 \
12+
--user="$GITBASE_USER" \
13+
--password="$GITBASE_PASSWORD" \
14+
--directories="$GITBASE_REPOS"

0 commit comments

Comments
 (0)