From e8a6f1521060cb8a2034951d84c09eadb4c8f4ec Mon Sep 17 00:00:00 2001 From: Anthony Lapenna Date: Tue, 31 Aug 2021 10:04:31 +1200 Subject: [PATCH] chore(build-system): update dev-toolkit (#4887) (#5543) * chore(build-system): update dev-toolkit * chore(build-system): update dev-toolkit * chore(build-system): update dev-toolkit Dockerfile * chore(build-system): update gruntfile * chore(build-system): gruntfile update * chore(build-system): better support for private git repositories * Update toolkit.Dockerfile * merge develop into toolkit-update * merge develop into toolkit-update --- build/linux/dev-toolkit/run.sh | 99 +++++++++++++++++++ .../{ => dev-toolkit}/toolkit.Dockerfile | 41 +++++--- gruntfile.js | 3 +- 3 files changed, 130 insertions(+), 13 deletions(-) create mode 100755 build/linux/dev-toolkit/run.sh rename build/linux/{ => dev-toolkit}/toolkit.Dockerfile (52%) diff --git a/build/linux/dev-toolkit/run.sh b/build/linux/dev-toolkit/run.sh new file mode 100755 index 000000000..d856cb7c1 --- /dev/null +++ b/build/linux/dev-toolkit/run.sh @@ -0,0 +1,99 @@ +#!/usr/bin/env bash + +# Script used to init the Portainer development environment inside the dev-toolkit image + +### COLOR OUTPUT ### + +ESeq="\x1b[" +RCol="$ESeq"'0m' # Text Reset + +# Regular Bold Underline High Intensity BoldHigh Intens Background High Intensity Backgrounds +Bla="$ESeq"'0;30m'; BBla="$ESeq"'1;30m'; UBla="$ESeq"'4;30m'; IBla="$ESeq"'0;90m'; BIBla="$ESeq"'1;90m'; On_Bla="$ESeq"'40m'; On_IBla="$ESeq"'0;100m'; +Red="$ESeq"'0;31m'; BRed="$ESeq"'1;31m'; URed="$ESeq"'4;31m'; IRed="$ESeq"'0;91m'; BIRed="$ESeq"'1;91m'; On_Red="$ESeq"'41m'; On_IRed="$ESeq"'0;101m'; +Gre="$ESeq"'0;32m'; BGre="$ESeq"'1;32m'; UGre="$ESeq"'4;32m'; IGre="$ESeq"'0;92m'; BIGre="$ESeq"'1;92m'; On_Gre="$ESeq"'42m'; On_IGre="$ESeq"'0;102m'; +Yel="$ESeq"'0;33m'; BYel="$ESeq"'1;33m'; UYel="$ESeq"'4;33m'; IYel="$ESeq"'0;93m'; BIYel="$ESeq"'1;93m'; On_Yel="$ESeq"'43m'; On_IYel="$ESeq"'0;103m'; +Blu="$ESeq"'0;34m'; BBlu="$ESeq"'1;34m'; UBlu="$ESeq"'4;34m'; IBlu="$ESeq"'0;94m'; BIBlu="$ESeq"'1;94m'; On_Blu="$ESeq"'44m'; On_IBlu="$ESeq"'0;104m'; +Pur="$ESeq"'0;35m'; BPur="$ESeq"'1;35m'; UPur="$ESeq"'4;35m'; IPur="$ESeq"'0;95m'; BIPur="$ESeq"'1;95m'; On_Pur="$ESeq"'45m'; On_IPur="$ESeq"'0;105m'; +Cya="$ESeq"'0;36m'; BCya="$ESeq"'1;36m'; UCya="$ESeq"'4;36m'; ICya="$ESeq"'0;96m'; BICya="$ESeq"'1;96m'; On_Cya="$ESeq"'46m'; On_ICya="$ESeq"'0;106m'; +Whi="$ESeq"'0;37m'; BWhi="$ESeq"'1;37m'; UWhi="$ESeq"'4;37m'; IWhi="$ESeq"'0;97m'; BIWhi="$ESeq"'1;97m'; On_Whi="$ESeq"'47m'; On_IWhi="$ESeq"'0;107m'; + +printSection() { + echo -e "${BIYel}>>>> ${BIWhi}${1}${RCol}" +} + +info() { + echo -e "${BIWhi}${1}${RCol}" +} + +success() { + echo -e "${BIGre}${1}${RCol}" +} + +error() { + echo -e "${BIRed}${1}${RCol}" +} + +errorAndExit() { + echo -e "${BIRed}${1}${RCol}" + exit 1 +} + +### !COLOR OUTPUT ### + +SETUP_FILE=/setup-done + +display_configuration() { + info "Portainer dev-toolkit container configuration" + info "Go version" + /usr/local/go/bin/go version + info "Node version" + node -v + info "Yarn version" + yarn -v + info "Docker version" + docker version +} + +main() { + [[ -z $PUSER ]] && errorAndExit "Unable to find PUSER environment variable. Please ensure PUSER is set before running this script." + [[ -z $PUID ]] && errorAndExit "Unable to find PUID environment variable. Please ensure PUID is set before running this script." + [[ -z $PGID ]] && errorAndExit "Unable to find PGID environment variable. Please ensure PGID is set before running this script." + [[ -z $DOCKERGID ]] && errorAndExit "Unable to find DOCKERGID environment variable. Please ensure DOCKERGID is set before running this script." + + if [[ -f "${SETUP_FILE}" ]]; then + info "Portainer dev-toolkit container already configured." + display_configuration + else + info "Creating user group..." + groupadd -g $PGID $PUSER + + info "Creating user..." + useradd -l -u $PUID -g $PUSER $PUSER + + info "Setting up home..." + install -d -m 0755 -o $PUSER -g $PUSER /home/$PUSER + + info "Configuring Docker..." + groupadd -g $DOCKERGID docker + usermod -aG docker $PUSER + + info "Configuring Go..." + echo "PATH=\"$PATH:/usr/local/go/bin\"" > /etc/environment + + info "Configuring Git..." + su $PUSER -c "git config --global url.git@github.com:.insteadOf https://github.com/" + + info "Configuring SSH..." + mkdir /home/$PUSER/.ssh + cp /host-ssh/* /home/$PUSER/.ssh/ + chown -R $PUSER:$PUSER /home/$PUSER/.ssh + + touch "${SETUP_FILE}" + success "Portainer dev-toolkit container successfully configured." + + display_configuration + fi +} + +main +su $PUSER -s "$@" \ No newline at end of file diff --git a/build/linux/toolkit.Dockerfile b/build/linux/dev-toolkit/toolkit.Dockerfile similarity index 52% rename from build/linux/toolkit.Dockerfile rename to build/linux/dev-toolkit/toolkit.Dockerfile index dc3f901a2..32470cc3b 100644 --- a/build/linux/toolkit.Dockerfile +++ b/build/linux/dev-toolkit/toolkit.Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu +FROM ubuntu:20.04 # Expose port for the Portainer UI and Edge server EXPOSE 9000 @@ -14,13 +14,30 @@ ARG GO_VERSION=go1.16.6.linux-amd64 # Install packages RUN apt-get update --fix-missing && apt-get install -qq \ - dialog \ - apt-utils \ - curl \ - build-essential \ - nodejs \ - git \ - wget + dialog \ + apt-utils \ + curl \ + build-essential \ + git \ + wget \ + apt-transport-https \ + ca-certificates \ + gnupg-agent \ + software-properties-common + +# Install Docker CLI +RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - \ + && add-apt-repository \ + "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ + $(lsb_release -cs) \ + stable" \ + && apt-get update \ + && apt-get install -y docker-ce-cli + + +# Install NodeJS +RUN curl -fsSL https://deb.nodesource.com/setup_14.x | bash - \ + && apt-get install -y nodejs # Install Yarn RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \ @@ -33,8 +50,8 @@ RUN cd /tmp \ && tar -xf ${GO_VERSION}.tar.gz \ && mv go /usr/local -# Configure Go -ENV PATH "$PATH:/usr/local/go/bin" +# Copy run script +COPY run.sh / +RUN chmod +x /run.sh -# Confirm installation -RUN go version && node -v && yarn -v +ENTRYPOINT ["/run.sh"] diff --git a/gruntfile.js b/gruntfile.js index f9940229d..6dbbc1c00 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -7,6 +7,7 @@ var arch = os.arch(); if (arch === 'x64') arch = 'amd64'; var portainer_data = '${PORTAINER_DATA:-/tmp/portainer}'; +var portainer_root = process.env.PORTAINER_PROJECT ? process.env.PORTAINER_PROJECT : process.env.PWD; module.exports = function (grunt) { loadGruntTasks(grunt, { @@ -174,7 +175,7 @@ function shell_build_binary_azuredevops(p, a) { function shell_run_container() { return [ 'docker rm -f portainer', - 'docker run -d -p 8000:8000 -p 9000:9000 -v $(pwd)/dist:/app -v ' + + 'docker run -d -p 8000:8000 -p 9000:9000 -v ' + portainer_root + '/dist:/app -v ' + portainer_data + ':/data -v /var/run/docker.sock:/var/run/docker.sock:z -v /var/run/docker.sock:/var/run/alternative.sock:z -v /tmp:/tmp --name portainer portainer/base /app/portainer', ].join(';');