Compare commits
3 Commits
2.18.4
...
toolkit-v2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c3ac35f02 | ||
|
|
140ec51143 | ||
|
|
327bbd4ca7 |
112
build/linux/dev-toolkit/README.md
Normal file
112
build/linux/dev-toolkit/README.md
Normal file
@@ -0,0 +1,112 @@
|
||||
The entire Portainer development stack inside a container (including the IDE!).
|
||||
|
||||
Inspired/made after reading https://www.gitpod.io/blog/openvscode-server-launch
|
||||
|
||||
## Requirements
|
||||
|
||||
All you need to have installed is Docker.
|
||||
|
||||
## (optional) Build the toolkit image locally
|
||||
|
||||
Assuming the toolkit is not built/provided by Portainer or you want to tweak it, use the following instructions to build the toolkit locally:
|
||||
|
||||
```
|
||||
cd build/linux/dev-toolkit/
|
||||
docker build -t portainer-development-toolkit -f toolkit.Dockerfile .
|
||||
```
|
||||
|
||||
Note: If using WSL2, you might need to use the `--network host` build option.
|
||||
|
||||
## How to use it
|
||||
|
||||
Assuming the image is built and available under `portainer-development-toolkit`.
|
||||
|
||||
Start the development environment inside a container, this must be executed in the root folder of the Portainer project:
|
||||
|
||||
```
|
||||
# First, let's create a space to persist our code, dependencies and VS extensions
|
||||
$ mkdir -pv /home/alapenna/workspaces/portainer-toolkit
|
||||
|
||||
# Export the space as an env var
|
||||
$ export TOOLKIT_ROOT=/home/alapenna/workspaces/portainer-toolkit
|
||||
|
||||
# Run the toolkit
|
||||
$ docker run -it --init \
|
||||
-p 3000:3000 \
|
||||
-p 9000:9000 -p 9443:9443 -p 8000:8000 \
|
||||
-v ${TOOLKIT_ROOT}:/home/workspace:cached \
|
||||
--name portainer-development-toolkit \
|
||||
portainer-development-toolkit
|
||||
```
|
||||
|
||||
Now you can access VScode directly at http://localhost:3000 and start coding (almost)!
|
||||
|
||||
## Legacy deployment (running as a container on the host)
|
||||
|
||||
You can still run Portainer through a base container with the host but you will need to pass extra parameters when deploying the toolkit container:
|
||||
|
||||
```
|
||||
$ docker run -it --init -p 3000:3000 \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
-v ${TOOLKIT_ROOT}:/home/workspace:cached \
|
||||
-e PORTAINER_PROJECT=${TOOLKIT_ROOT}/portainer \
|
||||
--name portainer-development-toolkit \
|
||||
portainer-development-toolkit
|
||||
```
|
||||
|
||||
### Why do I need PORTAINER_PROJECT?
|
||||
|
||||
This environment variable defines where the Portainer project root folder resides on your machine and will be used by Docker to bind mount the `/dist` folder when deploying the local development Portainer instance.
|
||||
|
||||
# What's next?
|
||||
|
||||
## Extensibility
|
||||
|
||||
Developers should be able to customize the environment to their liking (I prefer work with zsh as a shell for example), we need to provide instructions on how they can use this build system as a base and extend it to their liking.
|
||||
|
||||
## Improved dev workflow/UX
|
||||
|
||||
Multiple steps are required for the dev environment to be ready:
|
||||
|
||||
- Downloading the front-end (FE) dependencies (aka node_modules)
|
||||
- Downloading the back-end (BE) dependencies (go libraries)
|
||||
- Downloading the runtime BE assets (Docker, Kubernetes binaries...)
|
||||
|
||||
There should be a way to install/refresh these via yarn:
|
||||
|
||||
- yarn fe:install and yarn fe:update, shortcuts: yarn fe:i and yarn fe:u
|
||||
|
||||
- this is actually done via yarn to install, and then yarn add/upgrade/delete for package management
|
||||
|
||||
- yarn be:install and yarn be:update, shortcuts: yarn be:i and yarn be:u
|
||||
- this is actually done through go build, and then go get -u when another dependency version is needed
|
||||
- yarn assets:install and yarn assets:update, shortcuts yarn assets:i and yarn assets:u
|
||||
|
||||
There should be a way to init the environment for the first time to install all the dependencies:
|
||||
|
||||
- yarn init
|
||||
- instead there should be a command that will build backend+frontend and run it
|
||||
|
||||
Once the environment is ready, a developer can work on different dimensions:
|
||||
|
||||
- The FE
|
||||
- The BE
|
||||
- Both
|
||||
|
||||
(?) A developer should be able to run Portainer in multiple ways (?)
|
||||
|
||||
- Directly running the binary
|
||||
- Starting Portainer running inside a container
|
||||
|
||||
A developer should be able to:
|
||||
|
||||
- Rebuild the backend without restarting the entire webpack/watch process
|
||||
- Clean the entire project (FE+BE)
|
||||
|
||||
## Updating the toolkit
|
||||
|
||||
A developer should be able to update the toolkit to a more recent version (to support a newer Golang version for example) without having to rebuild the entire system/container.
|
||||
|
||||
## VSCode + zsh
|
||||
|
||||
https://medium.com/fbdevclagos/updating-visual-studio-code-default-terminal-shell-from-bash-to-zsh-711c40d6f8dc
|
||||
@@ -1,99 +0,0 @@
|
||||
#!/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 "$@"
|
||||
@@ -1,17 +1,17 @@
|
||||
FROM ubuntu:20.04
|
||||
FROM gitpod/openvscode-server:latest
|
||||
|
||||
# Expose port for the Portainer UI and Edge server
|
||||
EXPOSE 9000
|
||||
EXPOSE 3000
|
||||
EXPOSE 9443
|
||||
EXPOSE 9000
|
||||
EXPOSE 8000
|
||||
|
||||
WORKDIR /src/portainer
|
||||
USER root
|
||||
|
||||
# Set TERM as noninteractive to suppress debconf errors
|
||||
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
|
||||
|
||||
# Set default go version
|
||||
ARG GO_VERSION=go1.16.6.linux-amd64
|
||||
ARG GO_VERSION=go1.16.9.linux-amd64
|
||||
|
||||
# Install packages
|
||||
RUN apt-get update --fix-missing && apt-get install -qq \
|
||||
@@ -51,8 +51,5 @@ RUN cd /tmp \
|
||||
&& tar -xf ${GO_VERSION}.tar.gz \
|
||||
&& mv go /usr/local
|
||||
|
||||
# Copy run script
|
||||
COPY run.sh /
|
||||
RUN chmod +x /run.sh
|
||||
|
||||
ENTRYPOINT ["/run.sh"]
|
||||
# Configuring Golang
|
||||
ENV PATH "$PATH:/usr/local/go/bin"
|
||||
|
||||
@@ -138,7 +138,6 @@ function shell_build_binary_azuredevops(platform, arch) {
|
||||
}
|
||||
|
||||
function shell_run_container() {
|
||||
const portainerData = '${PORTAINER_DATA:-/tmp/portainer}';
|
||||
const portainerRoot = process.env.PORTAINER_PROJECT ? process.env.PORTAINER_PROJECT : process.env.PWD;
|
||||
|
||||
return `
|
||||
@@ -148,7 +147,7 @@ function shell_run_container() {
|
||||
-p 9000:9000 \
|
||||
-p 9443:9443 \
|
||||
-v ${portainerRoot}/dist:/app \
|
||||
-v ${portainerData}:/data \
|
||||
-v portainer_dev:/data \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock:z \
|
||||
-v /var/run/docker.sock:/var/run/alternative.sock:z \
|
||||
-v /tmp:/tmp \
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
"dev:client": "grunt clean:client && webpack-dev-server --config=./webpack/webpack.develop.js",
|
||||
"dev:client:prod": "grunt clean:client && webpack-dev-server --config=./webpack/webpack.production.js",
|
||||
"dev:nodl": "grunt clean:server && grunt clean:client && grunt build:server && grunt start:client",
|
||||
"start:toolkit": "grunt start:toolkit",
|
||||
"build:server:offline": "cd ./api/cmd/portainer && CGO_ENABLED=0 go build --installsuffix cgo --ldflags '-s' && mv -f portainer ../../../dist/portainer",
|
||||
"clean:all": "grunt clean:all",
|
||||
"format": "prettier --loglevel warn --write \"**/*.{js,css,html}\"",
|
||||
|
||||
Reference in New Issue
Block a user