Skip to content

Commit

Permalink
Improve docker environment (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
oshirohugo authored Apr 18, 2024
1 parent c4aae62 commit b7fbbd6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
27 changes: 19 additions & 8 deletions .config/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ ARG grafana_image=grafana-enterprise

FROM grafana/${grafana_image}:${grafana_version}

ARG development=true

ARG GO_VERSION=1.21.6
ARG GO_ARCH=amd64

ENV DEV "${development}"

# Make it as simple as possible to access the grafana instance for development purposes
# Do NOT enable these settings in a public facing / production grafana instance
ENV GF_AUTH_ANONYMOUS_ORG_ROLE "Admin"
Expand All @@ -22,38 +26,45 @@ WORKDIR $GF_PATHS_HOME

USER root


# Installing supervisor and inotify-tools
RUN if grep -i -q alpine /etc/issue; then \
apk add supervisor inotify-tools git; \
RUN if [ "${development}" = "true" ]; then \
if grep -i -q alpine /etc/issue; then \
apk add supervisor inotify-tools git; \
elif grep -i -q ubuntu /etc/issue; then \
DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get install -y supervisor inotify-tools git && \
rm -rf /var/lib/apt/lists/*; \
else \
echo 'ERROR: Unsupported base image' && /bin/false; \
fi \
fi

COPY supervisord/supervisord.conf /etc/supervisor.d/supervisord.ini
COPY supervisord/supervisord.conf /etc/supervisor/conf.d/supervisord.conf


# Installing Go
RUN curl -O -L https://golang.org/dl/go${GO_VERSION}.linux-${GO_ARCH}.tar.gz && \
RUN if [ "${development}" = "true" ]; then \
curl -O -L https://golang.org/dl/go${GO_VERSION}.linux-${GO_ARCH}.tar.gz && \
rm -rf /usr/local/go && \
tar -C /usr/local -xzf go${GO_VERSION}.linux-${GO_ARCH}.tar.gz && \
echo "export PATH=$PATH:/usr/local/go/bin:~/go/bin" >> ~/.bashrc && \
rm -f go${GO_VERSION}.linux-${GO_ARCH}.tar.gz
rm -f go${GO_VERSION}.linux-${GO_ARCH}.tar.gz; \
fi

# Installing delve for debugging
RUN /usr/local/go/bin/go install github.com/go-delve/delve/cmd/dlv@latest
RUN if [ "${development}" = "true" ]; then \
/usr/local/go/bin/go install github.com/go-delve/delve/cmd/dlv@latest; \
fi

# Installing mage for plugin (re)building
RUN git clone https://github.com/magefile/mage; \
RUN if [ "${development}" = "true" ]; then \
git clone https://github.com/magefile/mage; \
cd mage; \
export PATH=$PATH:/usr/local/go/bin; \
go run bootstrap.go
go run bootstrap.go; \
fi

# Inject livereload script into grafana index.html
RUN sed -i 's|</body>|<script src="http://localhost:35729/livereload.js"></script></body>|g' /usr/share/grafana/public/views/index.html
Expand Down
8 changes: 8 additions & 0 deletions .config/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/bin/sh

if [ "${DEV}" = "false" ]; then
echo "Starting test mode"
exec /run.sh
fi

echo "Starting development mode"

if grep -i -q alpine /etc/issue; then
exec /usr/bin/supervisord -c /etc/supervisord.conf
elif grep -i -q ubuntu /etc/issue; then
Expand All @@ -8,3 +15,4 @@ else
echo 'ERROR: Unsupported base image'
exit 1
fi

2 changes: 2 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ services:
args:
grafana_image: ${GRAFANA_IMAGE:-grafana-enterprise}
grafana_version: ${GRAFANA_VERSION:-10.2.4}
# remove the following line when developing to have backend debugger
development: "false"
ports:
- 3000:3000
volumes:
Expand Down

0 comments on commit b7fbbd6

Please sign in to comment.