mirror of https://github.com/grafana/grafana
Toolkit: simplify the plugin ci docker image (#23267)
* removing src dir on publish * Moved from binary to native typescript 1. Moved to a native typescrpt github publish using the existing github client. 2. Change dist.js to detect running in a linked environment. Todo: Optimize docker image for build size. * Optimized build of docker container Much smaller. From 5.47 gb to 2.88 * Feedback from discussion with Ryan - Added gget for getting grafana versions - Added infrastructure for testing - Uploaded new docker image * Fixed typo... Not sure what happened there :) * Added command to download canary * small fix for displaying versions in help * Removed --dev option Should really just rename version to (ex: 1.2.0-dev) * removing src dir on publish * Moved from binary to native typescript 1. Moved to a native typescrpt github publish using the existing github client. 2. Change dist.js to detect running in a linked environment. Todo: Optimize docker image for build size. * Optimized build of docker container Much smaller. From 5.47 gb to 2.88 * Feedback from discussion with Ryan - Added gget for getting grafana versions - Added infrastructure for testing - Uploaded new docker image * Fixed typo... Not sure what happened there :) * Added command to download canary * small fix for displaying versions in help * Removed --dev option Should really just rename version to (ex: 1.2.0-dev)pull/23272/head
parent
06ba5201bb
commit
c5252f1b64
@ -1,5 +1,22 @@ |
||||
#!/usr/bin/env node
|
||||
|
||||
// This bin is used for cli installed from npm
|
||||
const fs = require('fs'); |
||||
|
||||
require('../src/cli/index.js').run(); |
||||
entrypoint = () => { |
||||
const defaultEntryPoint = '../src/cli/index.js'; |
||||
// We are running in dev mode. Don't use compiled binaries, rather use the dev entrypoint.
|
||||
if (fs.existsSync(`${process.env['HOME']}/.config/yarn/link/@grafana/toolkit`)) { |
||||
console.log('Running in linked mode'); |
||||
return `${__dirname}/grafana-toolkit.js`; |
||||
} |
||||
|
||||
// We are using npx, and a relative path does not find index.js
|
||||
if (!fs.existsSync(defaultEntryPoint) && fs.existsSync(`${__dirname}/../dist/src/cli/index.js`)) { |
||||
return `${__dirname}/../dist/src/cli/index.js`; |
||||
} |
||||
|
||||
// The default entrypoint must exist, return it now.
|
||||
return defaultEntryPoint; |
||||
}; |
||||
|
||||
require(entrypoint()).run(); |
||||
|
@ -1,51 +1,6 @@ |
||||
FROM circleci/node:12-browsers |
||||
USER root |
||||
WORKDIR /tmp |
||||
|
||||
# Install Go |
||||
ADD https://dl.google.com/go/go1.14.linux-amd64.tar.gz /tmp |
||||
RUN echo 08df79b46b0adf498ea9f320a0f23d6ec59e9003660b4c9c1ce8e5e2c6f823ca go1.14.linux-amd64.tar.gz | sha256sum --check --status |
||||
RUN tar -C /usr/local -xf go1.14.linux-amd64.tar.gz |
||||
|
||||
# Install golangci-lint |
||||
ADD https://github.com/golangci/golangci-lint/releases/download/v1.23.7/golangci-lint-1.23.7-linux-amd64.tar.gz /tmp |
||||
RUN echo 34df1794a2ea8e168b3c98eed3cc0f3e13ed4cba735e4e40ef141df5c41bc086 golangci-lint-1.23.7-linux-amd64.tar.gz | sha256sum --check --status |
||||
RUN tar xf golangci-lint-1.23.7-linux-amd64.tar.gz |
||||
RUN mv golangci-lint-1.23.7-linux-amd64/golangci-lint /usr/local/bin |
||||
RUN ln -s /usr/local/go/bin/go /usr/local/bin/go |
||||
RUN ln -s /usr/local/go/bin/gofmt /usr/local/bin/gofmt |
||||
RUN chmod 755 /usr/local/bin/golangci-lint |
||||
|
||||
# Install dependencies |
||||
RUN apt-get update -y && apt-get install -y adduser libfontconfig1 locate && /bin/rm -rf /var/lib/apt/lists/* |
||||
|
||||
# Install code climate |
||||
ADD https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 /usr/local/bin/cc-test-reporter |
||||
RUN echo 38f2442892027f61a07f52c845818750261b2ba58bffb043a582495339d37c05 /usr/local/bin/cc-test-reporter | sha256sum --check --status |
||||
RUN chmod +x /usr/local/bin/cc-test-reporter |
||||
|
||||
# Download, but don't install previous grafana releases |
||||
RUN mkdir -pv /usr/local/grafana/deb |
||||
ADD https://dl.grafana.com/oss/release/grafana_6.6.2_amd64.deb /usr/local/grafana/deb |
||||
ADD https://dl.grafana.com/oss/release/grafana_6.5.3_amd64.deb /usr/local/grafana/deb |
||||
ADD https://dl.grafana.com/oss/release/grafana_6.4.5_amd64.deb /usr/local/grafana/deb |
||||
ADD https://dl.grafana.com/oss/release/grafana_6.3.7_amd64.deb /usr/local/grafana/deb |
||||
|
||||
# Perform user specific initialization |
||||
USER circleci |
||||
RUN mkdir -pv ${HOME}/plugin ${HOME}/go/bin ${HOME}/bin ${HOME}/src ${HOME}/tmp |
||||
|
||||
# Install grafana release with yarn |
||||
RUN git clone https://github.com/grafana/grafana.git ${HOME}/src/grafana |
||||
WORKDIR /home/circleci/src/grafana |
||||
RUN git checkout tags/v$(curl -s https://raw.githubusercontent.com/grafana/grafana/master/latest.json | jq -r '.stable') |
||||
RUN yarn cache clean && yarn install --frozen-lockfile |
||||
|
||||
# Install Mage |
||||
RUN git clone https://github.com/magefile/mage.git ${HOME}/src/mage |
||||
WORKDIR /home/circleci/src/mage |
||||
RUN go run bootstrap.go |
||||
|
||||
ENV PATH /home/circleci/go/bin:/usr/local/go/bin:/home/circleci/.local/bin:/home/circleci/bin:${PATH} |
||||
WORKDIR /home/circleci/plugin |
||||
|
||||
ADD scripts scripts |
||||
WORKDIR scripts |
||||
RUN ./deploy.sh |
||||
ADD install/gget /usr/local/bin/gget |
||||
|
@ -0,0 +1,8 @@ |
||||
#!/bin/bash |
||||
source ./common.sh |
||||
|
||||
output=$(docker build . | tee /dev/tty) |
||||
hash=$(echo "$output" | tail -1 | sed -ne "s/^Successfully built \(.*\)/\1/p") |
||||
docker tag "$hash" $DOCKER_IMAGE_NAME:latest |
||||
docker push $DOCKER_IMAGE_NAME:latest |
||||
|
@ -0,0 +1,7 @@ |
||||
#!/bin/bash |
||||
|
||||
## |
||||
## Common variable declarations |
||||
## |
||||
|
||||
DOCKER_IMAGE_NAME="srclosson/grafana-plugin-ci" |
@ -0,0 +1,63 @@ |
||||
#!/bin/bash |
||||
## |
||||
# gget |
||||
# A script to get and install grafana versions |
||||
# for usage information see "show_help" below. |
||||
# |
||||
|
||||
latest=$(curl -s 'https://raw.githubusercontent.com/grafana/grafana/master/latest.json' | jq -r '.stable') |
||||
canary=$(curl -s "https://grafana.com/api/grafana/versions" | jq ".items[0].version" | tr -d '"') |
||||
|
||||
show_help() { |
||||
echo "Usage: gget <version>" |
||||
echo "" |
||||
echo "where <version> can be:" |
||||
echo " 1) A version from https://grafana.com/grafana/download (ex x.y.z)" |
||||
echo " 2) latest (currently $latest)" |
||||
echo " 3) canary (currently $canary)" |
||||
echo "" |
||||
echo " -h, --help: Display this help message" |
||||
echo "" |
||||
exit 0 |
||||
} |
||||
|
||||
opts=$(getopt -o h --long help -n 'gget' -- "$@") |
||||
[ $? -eq 0 ] || { |
||||
show_help |
||||
} |
||||
|
||||
eval set -- "$opts" |
||||
while true; do |
||||
case "$1" in |
||||
-h | --help) |
||||
show_help |
||||
;; |
||||
--) |
||||
shift |
||||
break |
||||
;; |
||||
*) |
||||
break |
||||
;; |
||||
esac |
||||
shift |
||||
done |
||||
|
||||
[ -z "$1" ] && show_help |
||||
|
||||
# Make sure the script is being run as root |
||||
if [ $EUID -ne 0 ]; then |
||||
echo "This script must be run as root" |
||||
exit 1 |
||||
fi |
||||
|
||||
## |
||||
# MAIN |
||||
# |
||||
# Enough setup, let's actually do something |
||||
# |
||||
version=$1 |
||||
[ "$version" == "latest" ] && version="$latest" |
||||
[ "$version" == "canary" ] && version="$canary" |
||||
wget "https://dl.grafana.com/oss/release/grafana_${version}_amd64.deb" -O "/tmp/grafana_${version}_amd64.deb" |
||||
dpkg -i "/tmp/grafana_${version}_amd64.deb" && /bin/rm -rfv "/tmp/grafana_${version}_amd64.deb" |
@ -0,0 +1,38 @@ |
||||
#!/bin/bash |
||||
|
||||
## |
||||
# Script to deploy a docker image. Must return exit code 0 |
||||
# |
||||
do_exit() { |
||||
message="$1" |
||||
exit_code="$2" |
||||
|
||||
echo "$message" |
||||
exit $exit_code |
||||
} |
||||
|
||||
|
||||
## |
||||
# Get file, get's a file, validates the SHA |
||||
# @param filename |
||||
# @param expected sha value |
||||
# @returns 0 if successful, -1 of checksum validation failed. |
||||
# |
||||
get_file () { |
||||
[ -n "$1" ] && url=$1 || do_exit "url required" -1 |
||||
[ -n "$2" ] && dest=$2 || do_exit "destination required" -2 |
||||
sha=$3 |
||||
file=$(basename $dest) |
||||
|
||||
wget "$url" -O "$dest" |
||||
if [ -n "$sha" ]; then |
||||
echo "$sha $dest" | sha256sum --check --status || do_exit "Checksum validation failed for $file. Exiting" -1 |
||||
fi |
||||
} |
||||
|
||||
untar_file () { |
||||
[ -n "$1" ] && src=$1 || do_exit "src required" -1 |
||||
[ -n "$2" ] && dest=$2 || dest="/usr/local" |
||||
|
||||
tar -C "$dest" -xf "$src" && /bin/rm -rf "$src" |
||||
} |
@ -0,0 +1,3 @@ |
||||
#!/bin/bash |
||||
source "./deploy-common.sh" |
||||
|
@ -0,0 +1,43 @@ |
||||
#!/bin/bash |
||||
source "./deploy-common.sh" |
||||
|
||||
# Install Go |
||||
filename="go1.14.linux-amd64.tar.gz" |
||||
get_file "https://dl.google.com/go/$filename" "/tmp/$filename" "08df79b46b0adf498ea9f320a0f23d6ec59e9003660b4c9c1ce8e5e2c6f823ca" |
||||
untar_file "/tmp/$filename" |
||||
|
||||
|
||||
# Install golangci-lint |
||||
filename="golangci-lint-1.23.7-linux-amd64.tar.gz" |
||||
get_file "https://github.com/golangci/golangci-lint/releases/download/v1.23.7/$filename" \ |
||||
"/tmp/$filename" \ |
||||
"34df1794a2ea8e168b3c98eed3cc0f3e13ed4cba735e4e40ef141df5c41bc086" |
||||
untar_file "/tmp/$filename" |
||||
chmod 755 /usr/local/bin/golangci-lint |
||||
ln -s /usr/local/golangci-lint-1.23.7-linux-amd64/golangci-lint /usr/local/bin/golangci-lint |
||||
ln -s /usr/local/go/bin/go /usr/local/bin/go |
||||
ln -s /usr/local/go/bin/gofmt /usr/local/bin/gofmt |
||||
|
||||
# Install dependencies |
||||
apt-get update -y && apt-get install -y adduser libfontconfig1 locate && /bin/rm -rf /var/lib/apt/lists/* |
||||
|
||||
# Install code climate |
||||
get_file "https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64" \ |
||||
"/usr/local/bin/cc-test-reporter" \ |
||||
"38f2442892027f61a07f52c845818750261b2ba58bffb043a582495339d37c05" |
||||
chmod +x /usr/local/bin/cc-test-reporter |
||||
|
||||
# Install Mage |
||||
mkdir -pv /tmp/mage $HOME/go/bin |
||||
git clone https://github.com/magefile/mage.git /tmp/mage |
||||
pushd /tmp/mage && go run bootstrap.go && popd |
||||
mv $HOME/go/bin/mage /usr/local/bin |
||||
# Cleanup after yourself |
||||
/bin/rm -rf /tmp/mage |
||||
/bin/rm -rf $HOME/go |
||||
|
||||
# Perform user specific initialization |
||||
sudo -u circleci ./deploy-user.sh |
||||
|
||||
# Get the size down |
||||
/bin/rm -rf /var/lib/apt/lists |
@ -0,0 +1,8 @@ |
||||
version: '3' |
||||
services: |
||||
citest: |
||||
image: "circleci/node:12-browsers" |
||||
user: root |
||||
volumes: |
||||
- ../scripts:/home/circleci/scripts |
||||
- ../install:/home/circleci/install |
@ -0,0 +1,4 @@ |
||||
#!/bin/bash |
||||
|
||||
# Enter the docker container |
||||
docker-compose run citest bash -c "cd /home/circleci; exec bash --login -i" |
Loading…
Reference in new issue