Commit e487c681 by Arve Knudsen Committed by GitHub

Add Dockerfiles for Ubuntu (#20196)

* Build: Add /Dockerfile.ubuntu
* Build: Add packaging/docker/Dockerfile.ubuntu
* Build: Add grafana-docker-ubuntu-pr CircleCI job
* Build: Add CircleCI jobs for building master/release Ubuntu based Docker images
parent b9bc8ade
......@@ -395,6 +395,20 @@ jobs:
- run: cp enterprise-dist/grafana-enterprise-*.linux-amd64-musl.tar.gz packaging/docker/grafana-latest.linux-x64-musl.tar.gz
- run: cd packaging/docker && ./build-enterprise.sh "master"
grafana-docker-ubuntu-master:
machine:
image: circleci/classic:201808-01
steps:
- checkout
- attach_workspace:
at: .
- run: docker info
- run: docker run --privileged linuxkit/binfmt:v0.6
- run: cp dist/grafana-latest.linux-*.tar.gz packaging/docker
- run: cd packaging/docker && ./build-deploy.sh --ubuntu "master-${CIRCLE_SHA1}"
- run: rm packaging/docker/grafana-latest.linux-*.tar.gz
- run: cp enterprise-dist/grafana-enterprise-*.linux-amd64.tar.gz packaging/docker/grafana-latest.linux-x64.tar.gz
- run: cd packaging/docker && ./build-enterprise.sh --ubuntu "master"
grafana-docker-pr:
machine:
......@@ -408,6 +422,18 @@ jobs:
- run: cp dist/grafana-latest.linux-*.tar.gz packaging/docker
- run: cd packaging/docker && ./build.sh --fast "${CIRCLE_SHA1}"
grafana-docker-ubuntu-pr:
machine:
image: circleci/classic:201808-01
steps:
- checkout
- attach_workspace:
at: .
- run: docker info
- run: docker run --privileged linuxkit/binfmt:v0.6
- run: cp dist/grafana-latest.linux-*.tar.gz packaging/docker
- run: cd packaging/docker && ./build.sh --fast --ubuntu "${CIRCLE_SHA1}"
grafana-docker-release:
machine:
image: circleci/classic:201808-01
......@@ -423,6 +449,21 @@ jobs:
- run: cp enterprise-dist/grafana-enterprise-*.linux-amd64-musl.tar.gz packaging/docker/grafana-latest.linux-x64-musl.tar.gz
- run: cd packaging/docker && ./build-enterprise.sh "${CIRCLE_TAG}"
grafana-docker-ubuntu-release:
machine:
image: circleci/classic:201808-01
steps:
- checkout
- attach_workspace:
at: .
- run: docker info
- run: docker run --privileged linuxkit/binfmt:v0.6
- run: cp dist/grafana-latest.linux-*.tar.gz packaging/docker
- run: cd packaging/docker && ./build-deploy.sh --ubuntu "${CIRCLE_TAG}"
- run: rm packaging/docker/grafana-latest.linux-*.tar.gz
- run: cp enterprise-dist/grafana-enterprise-*.linux-amd64.tar.gz packaging/docker/grafana-latest.linux-x64.tar.gz
- run: cd packaging/docker && ./build-enterprise.sh --ubuntu "${CIRCLE_TAG}"
build-enterprise:
docker:
- image: grafana/build-container:1.2.11
......@@ -787,6 +828,18 @@ workflows:
- mysql-integration-test
- postgres-integration-test
filters: *filter-only-master
- grafana-docker-ubuntu-master:
requires:
- build-all
- build-all-enterprise
- test-backend
- test-frontend
- codespell
- lint-go
- shellcheck
- mysql-integration-test
- postgres-integration-test
filters: *filter-only-master
- deploy-enterprise-master:
requires:
- build-all
......@@ -880,6 +933,18 @@ workflows:
- mysql-integration-test
- postgres-integration-test
filters: *filter-only-release
- grafana-docker-ubuntu-release:
requires:
- build-all
- build-all-enterprise
- test-backend
- test-frontend
- codespell
- lint-go
- shellcheck
- mysql-integration-test
- postgres-integration-test
filters: *filter-only-release
- release-packages:
requires:
- build-all
......@@ -949,6 +1014,18 @@ workflows:
- postgres-integration-test
- cache-server-test
filters: *filter-not-release-or-master
- grafana-docker-ubuntu-pr:
requires:
- build-fast-package
- test-backend
- test-frontend
- codespell
- lint-go
- shellcheck
- mysql-integration-test
- postgres-integration-test
- cache-server-test
filters: *filter-not-release-or-master
- store-build-artifacts:
requires:
- build-fast-package
......
FROM golang:1.13.1 AS go-builder
WORKDIR /src/grafana
COPY go.mod go.sum ./
COPY vendor vendor/
RUN go mod verify
COPY build.go package.json ./
COPY pkg pkg/
RUN go run build.go build
FROM node:10.17 AS js-builder
# PhantomJS
RUN apt-get update && apt-get install -y curl &&\
curl -L https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 | tar xj &&\
cp phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs
WORKDIR /usr/src/app/
COPY package.json yarn.lock ./
COPY packages packages
RUN yarn install --pure-lockfile
COPY Gruntfile.js tsconfig.json tslint.json .browserslistrc ./
COPY public public
COPY scripts scripts
COPY emails emails
ENV NODE_ENV production
RUN ./node_modules/.bin/grunt build
FROM ubuntu:18.10
LABEL maintainer="Grafana team <hello@grafana.com>"
EXPOSE 3000
ARG GF_UID="472"
ARG GF_GID="472"
ENV PATH="/usr/share/grafana/bin:$PATH" \
GF_PATHS_CONFIG="/etc/grafana/grafana.ini" \
GF_PATHS_DATA="/var/lib/grafana" \
GF_PATHS_HOME="/usr/share/grafana" \
GF_PATHS_LOGS="/var/log/grafana" \
GF_PATHS_PLUGINS="/var/lib/grafana/plugins" \
GF_PATHS_PROVISIONING="/etc/grafana/provisioning"
WORKDIR $GF_PATHS_HOME
COPY conf conf
# We need font libs for phantomjs, and curl should be part of the image
RUN apt-get update && apt-get upgrade -y && apt-get install -y ca-certificates libfontconfig1 curl
RUN mkdir -p "$GF_PATHS_HOME/.aws" && \
addgroup --system --gid $GF_GID grafana && \
adduser --uid $GF_UID --system --ingroup grafana grafana && \
mkdir -p "$GF_PATHS_PROVISIONING/datasources" \
"$GF_PATHS_PROVISIONING/dashboards" \
"$GF_PATHS_PROVISIONING/notifiers" \
"$GF_PATHS_LOGS" \
"$GF_PATHS_PLUGINS" \
"$GF_PATHS_DATA" && \
cp conf/sample.ini "$GF_PATHS_CONFIG" && \
cp conf/ldap.toml /etc/grafana/ldap.toml && \
chown -R grafana:grafana "$GF_PATHS_DATA" "$GF_PATHS_HOME/.aws" "$GF_PATHS_LOGS" "$GF_PATHS_PLUGINS" "$GF_PATHS_PROVISIONING" && \
chmod -R 777 "$GF_PATHS_DATA" "$GF_PATHS_HOME/.aws" "$GF_PATHS_LOGS" "$GF_PATHS_PLUGINS" "$GF_PATHS_PROVISIONING"
# PhantomJS
COPY --from=js-builder /usr/local/bin/phantomjs /usr/local/bin/
COPY --from=go-builder /src/grafana/bin/linux-amd64/grafana-server /src/grafana/bin/linux-amd64/grafana-cli bin/
COPY --from=js-builder /usr/src/app/public public
COPY --from=js-builder /usr/src/app/tools tools
COPY tools/phantomjs/render.js tools/phantomjs/
COPY packaging/docker/run.sh /
USER grafana
ENTRYPOINT [ "/run.sh" ]
ARG BASE_IMAGE=ubuntu:18.10
FROM ${BASE_IMAGE} AS grafana-builder
ARG GRAFANA_TGZ="grafana-latest.linux-x64.tar.gz"
COPY ${GRAFANA_TGZ} /tmp/grafana.tar.gz
RUN mkdir /tmp/grafana && tar xfz /tmp/grafana.tar.gz --strip-components=1 -C /tmp/grafana
FROM ${BASE_IMAGE}
EXPOSE 3000
# Set DEBIAN_FRONTEND=noninteractive in environment at build-time
ARG DEBIAN_FRONTEND=noninteractive
ARG GF_UID="472"
ARG GF_GID="472"
ENV PATH=/usr/share/grafana/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
GF_PATHS_CONFIG="/etc/grafana/grafana.ini" \
GF_PATHS_DATA="/var/lib/grafana" \
GF_PATHS_HOME="/usr/share/grafana" \
GF_PATHS_LOGS="/var/log/grafana" \
GF_PATHS_PLUGINS="/var/lib/grafana/plugins" \
GF_PATHS_PROVISIONING="/etc/grafana/provisioning"
WORKDIR $GF_PATHS_HOME
# Install dependencies
# We need curl in the image, and if the architecture is x86-64, we need to install libfontconfig1 for PhantomJS
RUN if [ `arch` = "x86_64" ]; then \
apt-get update && apt-get upgrade -y && apt-get install -y ca-certificates libfontconfig1 curl && \
apt-get autoremove -y && rm -rf /var/lib/apt/lists/*; \
else \
apt-get update && apt-get upgrade -y && apt-get install -y ca-certificates curl && \
apt-get autoremove -y && rm -rf /var/lib/apt/lists/*; \
fi
COPY --from=grafana-builder /tmp/grafana "$GF_PATHS_HOME"
RUN mkdir -p "$GF_PATHS_HOME/.aws" && \
addgroup --system --gid $GF_GID grafana && \
adduser --system --uid $GF_UID --ingroup grafana grafana && \
mkdir -p "$GF_PATHS_PROVISIONING/datasources" \
"$GF_PATHS_PROVISIONING/dashboards" \
"$GF_PATHS_PROVISIONING/notifiers" \
"$GF_PATHS_LOGS" \
"$GF_PATHS_PLUGINS" \
"$GF_PATHS_DATA" && \
cp "$GF_PATHS_HOME/conf/sample.ini" "$GF_PATHS_CONFIG" && \
cp "$GF_PATHS_HOME/conf/ldap.toml" /etc/grafana/ldap.toml && \
chown -R grafana:grafana "$GF_PATHS_DATA" "$GF_PATHS_HOME/.aws" "$GF_PATHS_LOGS" "$GF_PATHS_PLUGINS" "$GF_PATHS_PROVISIONING" && \
chmod -R 777 "$GF_PATHS_DATA" "$GF_PATHS_HOME/.aws" "$GF_PATHS_LOGS" "$GF_PATHS_PLUGINS" "$GF_PATHS_PROVISIONING"
COPY ./run.sh /run.sh
USER grafana
ENTRYPOINT [ "/run.sh" ]
#!/bin/sh
set -e
OPT=""
UBUNTU_BASE=0
while [ "$1" != "" ]; do
case "$1" in
"--ubuntu")
OPT="${OPT} --ubuntu"
UBUNTU_BASE=1
echo "Ubuntu base image enabled"
shift
;;
* )
# unknown param causes args to be passed through to $@
break
;;
esac
done
_grafana_version=$1
./build.sh "$_grafana_version"
./build.sh ${OPT} "$_grafana_version"
docker login -u "$DOCKER_USER" -p "$DOCKER_PASS"
./push_to_docker_hub.sh "$_grafana_version"
./push_to_docker_hub.sh ${OPT} "$_grafana_version"
if echo "$_grafana_version" | grep -q "^master-"; then
./deploy_to_k8s.sh "grafana/grafana-dev:$_grafana_version"
if [ ${UBUNTU_BASE} = "0" ]; then
if echo "$_grafana_version" | grep -q "^master-"; then
./deploy_to_k8s.sh "grafana/grafana-dev:$_grafana_version"
fi
fi
#!/bin/sh
set -e
UBUNTU_BASE=0
while [ "$1" != "" ]; do
case "$1" in
"--ubuntu")
UBUNTU_BASE=1
echo "Ubuntu base image enabled"
shift
;;
* )
# unknown param causes args to be passed through to $@
break
;;
esac
done
_raw_grafana_tag=$1
_docker_repo=${2:-grafana/grafana-enterprise}
......@@ -10,16 +26,25 @@ else
_grafana_tag="${_raw_grafana_tag}"
fi
echo "Building and deploying ${_docker_repo}:${_grafana_tag}"
if [ ${UBUNTU_BASE} = "0" ]; then
TAG_SUFFIX=""
DOCKERFILE="Dockerfile"
else
TAG_SUFFIX="-ubuntu"
DOCKERFILE="Dockerfile.ubuntu"
fi
echo "Building and deploying ${_docker_repo}:${_grafana_tag}${TAG_SUFFIX}"
docker build \
--tag "${_docker_repo}:${_grafana_tag}"\
--tag "${_docker_repo}:${_grafana_tag}${TAG_SUFFIX}" \
--no-cache=true \
-f ${DOCKERFILE} \
.
docker push "${_docker_repo}:${_grafana_tag}"
docker push "${_docker_repo}:${_grafana_tag}${TAG_SUFFIX}"
if echo "$_raw_grafana_tag" | grep -q "^v" && echo "$_raw_grafana_tag" | grep -qv "beta"; then
docker tag "${_docker_repo}:${_grafana_tag}" "${_docker_repo}:latest"
docker push "${_docker_repo}:latest"
docker tag "${_docker_repo}:${_grafana_tag}${TAG_SUFFIX}" "${_docker_repo}:latest${TAG_SUFFIX}"
docker push "${_docker_repo}:latest${TAG_SUFFIX}"
fi
#!/bin/sh
set -e
BUILD_FAST=0
UBUNTU_BASE=0
while [ "$1" != "" ]; do
case "$1" in
......@@ -8,6 +11,11 @@ while [ "$1" != "" ]; do
echo "Fast build enabled"
shift
;;
"--ubuntu")
UBUNTU_BASE=1
echo "Ubuntu base image enabled"
shift
;;
* )
# unknown param causes args to be passed through to $@
break
......@@ -20,56 +28,78 @@ _docker_repo=${2:-grafana/grafana}
# If the tag starts with v, treat this as a official release
if echo "$_grafana_tag" | grep -q "^v"; then
_grafana_version=$(echo "${_grafana_tag}" | cut -d "v" -f 2)
_grafana_version=$(echo "${_grafana_tag}" | cut -d "v" -f 2)
else
_grafana_version=$_grafana_tag
_grafana_version=$_grafana_tag
fi
echo "Building ${_docker_repo}:${_grafana_version}"
if [ $UBUNTU_BASE = "0" ]; then
echo "Building ${_docker_repo}:${_grafana_version}"
else
echo "Building ${_docker_repo}:${_grafana_version}-ubuntu"
fi
export DOCKER_CLI_EXPERIMENTAL=enabled
# Build grafana image for a specific arch
docker_build () {
base_image=$1
grafana_tgz=$2
tag=$3
base_image=$1
grafana_tgz=$2
tag=$3
dockerfile=${4:-Dockerfile}
docker build \
--build-arg BASE_IMAGE=${base_image} \
--build-arg GRAFANA_TGZ=${grafana_tgz} \
--tag "${tag}" \
--no-cache=true .
--build-arg BASE_IMAGE=${base_image} \
--build-arg GRAFANA_TGZ=${grafana_tgz} \
--tag "${tag}" \
--no-cache=true \
-f "${dockerfile}" \
.
}
docker_tag_linux_amd64 () {
repo=$1
tag=$2
docker tag "${_docker_repo}:${_grafana_version}" "${repo}:${tag}"
repo=$1
tag=$2
docker tag "${_docker_repo}:${_grafana_version}" "${repo}:${tag}"
}
# Tag docker images of all architectures
docker_tag_all () {
repo=$1
tag=$2
docker_tag_linux_amd64 $1 $2
if [ $BUILD_FAST = "0" ]; then
docker tag "${_docker_repo}-arm32v7-linux:${_grafana_version}" "${repo}-arm32v7-linux:${tag}"
docker tag "${_docker_repo}-arm64v8-linux:${_grafana_version}" "${repo}-arm64v8-linux:${tag}"
fi
repo=$1
tag=$2
docker_tag_linux_amd64 $1 $2
if [ $BUILD_FAST = "0" ]; then
docker tag "${_docker_repo}-arm32v7-linux:${_grafana_version}" "${repo}-arm32v7-linux:${tag}"
docker tag "${_docker_repo}-arm64v8-linux:${_grafana_version}" "${repo}-arm64v8-linux:${tag}"
fi
}
docker_build "alpine:3.10" "grafana-latest.linux-x64-musl.tar.gz" "${_docker_repo}:${_grafana_version}"
if [ $BUILD_FAST = "0" ]; then
docker_build "arm32v7/alpine:3.10" "grafana-latest.linux-armv7-musl.tar.gz" "${_docker_repo}-arm32v7-linux:${_grafana_version}"
docker_build "arm64v8/alpine:3.10" "grafana-latest.linux-arm64-musl.tar.gz" "${_docker_repo}-arm64v8-linux:${_grafana_version}"
fi
# Tag as 'latest' for official release; otherwise tag as grafana/grafana:master
if echo "$_grafana_tag" | grep -q "^v"; then
docker_tag_all "${_docker_repo}" "latest"
# Create the expected tag for running the end to end tests successfully
docker tag "${_docker_repo}:${_grafana_version}" "grafana/grafana-dev:${_grafana_tag}"
if [ $UBUNTU_BASE = "0" ]; then
docker_build "alpine:3.10" "grafana-latest.linux-x64-musl.tar.gz" "${_docker_repo}:${_grafana_version}"
if [ $BUILD_FAST = "0" ]; then
docker_build "arm32v7/alpine:3.10" "grafana-latest.linux-armv7-musl.tar.gz" "${_docker_repo}-arm32v7-linux:${_grafana_version}"
docker_build "arm64v8/alpine:3.10" "grafana-latest.linux-arm64-musl.tar.gz" "${_docker_repo}-arm64v8-linux:${_grafana_version}"
fi
# Tag as 'latest' for official release; otherwise tag as grafana/grafana:master
if echo "$_grafana_tag" | grep -q "^v"; then
docker_tag_all "${_docker_repo}" "latest"
# Create the expected tag for running the end to end tests successfully
docker tag "${_docker_repo}:${_grafana_version}" "grafana/grafana-dev:${_grafana_tag}"
else
docker_tag_all "${_docker_repo}" "master"
docker tag "${_docker_repo}:${_grafana_version}" "grafana/grafana-dev:${_grafana_version}"
fi
else
docker_tag_all "${_docker_repo}" "master"
docker tag "${_docker_repo}:${_grafana_version}" "grafana/grafana-dev:${_grafana_version}"
docker_build "ubuntu:18.10" "grafana-latest.linux-x64.tar.gz" "${_docker_repo}:${_grafana_version}-ubuntu" Dockerfile.ubuntu
# Tag as 'latest-ubuntu' for official release; otherwise tag as grafana/grafana:master-ubuntu
if echo "$_grafana_tag" | grep -q "^v"; then
docker tag "${_docker_repo}:${_grafana_version}-ubuntu" "${_docker_repo}:latest-ubuntu"
# Create the expected tag for running the end to end tests successfully
docker tag "${_docker_repo}:${_grafana_version}-ubuntu" "grafana/grafana-dev:${_grafana_tag}-ubuntu"
else
docker tag "${_docker_repo}:${_grafana_version}-ubuntu" "${_docker_repo}:master-ubuntu"
docker tag "${_docker_repo}:${_grafana_version}-ubuntu" "grafana/grafana-dev:${_grafana_version}-ubuntu"
fi
fi
#!/bin/sh
set -e
UBUNTU_BASE=0
while [ "$1" != "" ]; do
case "$1" in
"--ubuntu")
UBUNTU_BASE=1
echo "Ubuntu base image enabled"
shift
;;
* )
# unknown param causes args to be passed through to $@
break
;;
esac
done
_grafana_tag=${1:-}
_docker_repo=${2:-grafana/grafana}
# If the tag starts with v, treat this as a official release
# If the tag starts with v, treat this as an official release
if echo "$_grafana_tag" | grep -q "^v"; then
_grafana_version=$(echo "${_grafana_tag}" | cut -d "v" -f 2)
else
......@@ -13,25 +29,33 @@ fi
export DOCKER_CLI_EXPERIMENTAL=enabled
echo "pushing ${_docker_repo}:${_grafana_version}"
if [ $UBUNTU_BASE = "0" ]; then
echo "pushing ${_docker_repo}:${_grafana_version}"
else
echo "pushing ${_docker_repo}:${_grafana_version}-ubuntu"
fi
docker_push_all () {
repo=$1
tag=$2
# Push each image individually
docker push "${repo}:${tag}"
docker push "${repo}-arm32v7-linux:${tag}"
docker push "${repo}-arm64v8-linux:${tag}"
if [ $UBUNTU_BASE = "0" ]; then
# Push each image individually
docker push "${repo}:${tag}"
docker push "${repo}-arm32v7-linux:${tag}"
docker push "${repo}-arm64v8-linux:${tag}"
# Create and push a multi-arch manifest
docker manifest create "${repo}:${tag}" \
"${repo}:${tag}" \
"${repo}-arm32v7-linux:${tag}" \
"${repo}-arm64v8-linux:${tag}"
# Create and push a multi-arch manifest
docker manifest create "${repo}:${tag}" \
"${repo}:${tag}" \
"${repo}-arm32v7-linux:${tag}" \
"${repo}-arm64v8-linux:${tag}"
docker manifest push "${repo}:${tag}"
docker manifest push "${repo}:${tag}"
else
docker push "${repo}:${tag}-ubuntu"
fi
}
if echo "$_grafana_tag" | grep -q "^v" && echo "$_grafana_tag" | grep -vq "beta"; then
......@@ -40,13 +64,25 @@ if echo "$_grafana_tag" | grep -q "^v" && echo "$_grafana_tag" | grep -vq "beta"
docker_push_all "${_docker_repo}" "${_grafana_version}"
# Push to the grafana-dev repository with the expected tag
# for running the end to end tests successfully
docker push "grafana/grafana-dev:${_grafana_tag}"
if [ ${UBUNTU_BASE} = "0" ]; then
docker push "grafana/grafana-dev:${_grafana_tag}"
else
docker push "grafana/grafana-dev:${_grafana_tag}-ubuntu"
fi
elif echo "$_grafana_tag" | grep -q "^v" && echo "$_grafana_tag" | grep -q "beta"; then
docker_push_all "${_docker_repo}" "${_grafana_version}"
# Push to the grafana-dev repository with the expected tag
# for running the end to end tests successfully
docker push "grafana/grafana-dev:${_grafana_tag}"
if [ ${UBUNTU_BASE} = "0" ]; then
docker push "grafana/grafana-dev:${_grafana_tag}"
else
docker push "grafana/grafana-dev:${_grafana_tag}-ubuntu"
fi
elif echo "$_grafana_tag" | grep -q "master"; then
docker_push_all "${_docker_repo}" "master"
docker push "grafana/grafana-dev:${_grafana_version}"
if [ ${UBUNTU_BASE} = "0" ]; then
docker push "grafana/grafana-dev:${_grafana_version}"
else
docker push "grafana/grafana-dev:${_grafana_version}-ubuntu"
fi
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment