diff --git a/CHANGELOG.md b/CHANGELOG.md index 70a7a99a2..353fa4699 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,6 +81,8 @@ None :) No unreleased features +* Merging zsh, bash and fish shells into one docker image called `c8y-shell`. ZSH is launched by default but other shells can be used by launching them manually inside the same container. It makes it easier to try out different shells. + * Support `$C8Y_HOME` and `$C8Y_SESSION_HOME` variables in settings * Support dotnotation in --data diff --git a/Makefile b/Makefile index 5c7ade878..96e0d1644 100644 --- a/Makefile +++ b/Makefile @@ -95,16 +95,9 @@ build_powershell: ## Build the powershell module build-docker: ## Build the docker images @cp tools/PSc8y/Dependencies/c8y.linux ./docker/c8y.linux - @cp tools/shell/c8y.plugin.zsh ./docker/c8y.plugin.zsh - @cp tools/shell/c8y.plugin.sh ./docker/c8y.plugin.sh - - @sudo docker build ./docker --file ./docker/zsh.dockerfile $(DOCKER_BUILD_ARGS) --build-arg C8Y_VERSION=$(VERSION) --tag $(TAG_PREFIX)c8y-zsh - @sudo docker build ./docker --file ./docker/bash.dockerfile $(DOCKER_BUILD_ARGS) --build-arg C8Y_VERSION=$(VERSION) --tag $(TAG_PREFIX)c8y-bash + @sudo docker build ./docker --file ./docker/shell.dockerfile $(DOCKER_BUILD_ARGS) --build-arg C8Y_VERSION=$(VERSION) --tag $(TAG_PREFIX)c8y-shell @sudo docker build ./docker --file ./docker/pwsh.dockerfile $(DOCKER_BUILD_ARGS) --tag $(TAG_PREFIX)c8y-pwsh - @rm ./docker/c8y.linux - @rm ./docker/c8y.plugin.zsh - @rm ./docker/c8y.plugin.sh # --------------------------------------------------------------- # Tests @@ -140,21 +133,13 @@ publish-release: ## Publish release # --------------------------------------------------------------- # Docker examples # --------------------------------------------------------------- -run-docker-bash: - sudo docker run -it --rm \ - -e C8Y_HOST=$$C8Y_HOST \ - -e C8Y_TENANT=$$C8Y_TENANT \ - -e C8Y_USER=$$C8Y_USER \ - -e C8Y_PASSWORD=$$C8Y_PASSWORD \ - c8y-bash - -run-docker-zsh: +run-docker-shell: sudo docker run -it --rm \ -e C8Y_HOST=$$C8Y_HOST \ -e C8Y_TENANT=$$C8Y_TENANT \ -e C8Y_USER=$$C8Y_USER \ -e C8Y_PASSWORD=$$C8Y_PASSWORD \ - c8y-zsh + c8y-shell run-docker-pwsh: sudo docker run -it --rm \ diff --git a/docker/bash.dockerfile b/docker/bash.dockerfile deleted file mode 100644 index e74d2722f..000000000 --- a/docker/bash.dockerfile +++ /dev/null @@ -1,25 +0,0 @@ -FROM alpine:3.11 - -ARG C8Y_VERSION=1.3.0 - -RUN apk update \ - && apk add curl unzip bash bash-completion vim jq \ - && adduser -S c8yuser \ - && mkdir -p /sessions \ - && chown c8yuser /sessions - -USER c8yuser -WORKDIR /home/c8yuser - -COPY ./c8y.linux /home/c8yuser/bin/c8y -COPY ./c8y.plugin.sh /home/c8yuser/ - -ENV PATH=${PATH}:/home/c8yuser/bin -ENV C8Y_SESSION_HOME=/sessions - -RUN echo "source /home/c8yuser/c8y.plugin.sh" >> /home/c8yuser/.bashrc \ - && bash -c "source ~/c8y.plugin.sh; c8y version" - -VOLUME [ "/sessions" ] - -ENTRYPOINT [ "/bin/bash" ] diff --git a/docker/pwsh.dockerfile b/docker/pwsh.dockerfile index cdf9d58a6..32c7eb91b 100644 --- a/docker/pwsh.dockerfile +++ b/docker/pwsh.dockerfile @@ -1,15 +1,18 @@ FROM mcr.microsoft.com/powershell:7.1.1-ubuntu-18.04 RUN apt-get update \ - && apt-get install -y vim \ - && rm -rf /var/lib/apt/lists/* + && apt-get install -y vim git \ + && rm -rf /var/lib/apt/lists/* \ + && git clone https://github.com/reubenmiller/go-c8y-cli-addons.git /root/.go-c8y-cli +ENV C8Y_HOME=/root/.go-c8y-cli ENV C8Y_SESSION_HOME=/sessions +ENV C8Y_INSTALL_OPTIONS="-AllowPrerelease" VOLUME [ "/sessions" ] COPY profile.ps1 /root/.config/powershell/Microsoft.PowerShell_profile.ps1 RUN pwsh -c "Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted; " \ - && pwsh -c "Install-Module PSc8y -Repository PSGallery -AllowClobber -Force" + && pwsh -c "Install-Module PSc8y -Repository PSGallery -AllowClobber $C8Y_INSTALL_OPTIONS -Force" ENTRYPOINT [ "pwsh", "-NoExit", "-c", "Import-Module PSc8y" ] diff --git a/docker/shell.dockerfile b/docker/shell.dockerfile new file mode 100644 index 000000000..92299faa6 --- /dev/null +++ b/docker/shell.dockerfile @@ -0,0 +1,60 @@ +FROM alpine:3.11 + +ARG USERNAME=c8yuser +ARG C8Y_VERSION=1.3.0 + +RUN apk update \ + && apk add curl unzip bash bash-completion zsh fish git vim jq \ + && adduser -S $USERNAME \ + && mkdir -p /sessions \ + && chown -R $USERNAME /sessions \ + && git clone https://github.com/reubenmiller/go-c8y-cli-addons.git /home/$USERNAME/.go-c8y-cli + +WORKDIR /home/$USERNAME + +USER $USERNAME +RUN sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)" -s --batch +USER root + +# add binary to path +ENV PATH=${PATH}:/home/$USERNAME/bin +ENV C8Y_SESSION_HOME=/sessions +COPY ./c8y.linux /home/$USERNAME/bin/c8y + + +# install plugins +RUN echo "source /home/$USERNAME/.go-c8y-cli/shell/c8y.plugin.sh" >> /home/$USERNAME/.bashrc \ + # && echo "export C8Y_SESSION_HOME=/sessions" >> /home/$USERNAME/.bashrc \ + && bash -c "c8y version" \ + # + # zsh + && mkdir -p /home/$USERNAME/.oh-my-zsh/custom/plugins/c8y/ \ + && cp /home/$USERNAME/.go-c8y-cli/shell/c8y.plugin.zsh /home/$USERNAME/.oh-my-zsh/custom/plugins/c8y/ \ + && sed -iE 's/^plugins=(\(.*\))/plugins=(\1 c8y)/' /home/$USERNAME/.zshrc \ + # + # Create completions before zsh runs otherwise + # it will not automatically load the completions until the user + # runs 'source ~/.zshrc' + && c8y completion zsh > /home/$USERNAME/.oh-my-zsh/custom/plugins/c8y/_c8y \ + # && echo "export C8Y_SESSION_HOME=/sessions" >> /home/$USERNAME/.zshrc \ + # + # fish + && mkdir -p /home/$USERNAME/.config/fish \ + && echo "source /home/$USERNAME/.go-c8y-cli/shell/c8y.plugin.fish" >> /home/$USERNAME/.config/fish/config.fish \ + # && echo "set -gx C8Y_SESSION_HOME /sessions" >> /home/$USERNAME/.config/fish/config.fish \ + && fish -c "c8y version" + + +# Working settings +RUN chown -R $USERNAME /home/$USERNAME + +# Prevent zsh plugins from affecting completions +# https://github.com/ohmyzsh/ohmyzsh/issues/1282 +# https://stackoverflow.com/questions/11916064/zsh-tab-completion-duplicating-command-name +ENV LANG=C.UTF-8 +ENV LC_ALL=C.UTF-8 + +USER $USERNAME +VOLUME [ "/sessions" ] + +ENTRYPOINT [ "/bin/zsh" ] diff --git a/docker/zsh.dockerfile b/docker/zsh.dockerfile deleted file mode 100644 index 5aeb95ab4..000000000 --- a/docker/zsh.dockerfile +++ /dev/null @@ -1,44 +0,0 @@ -FROM alpine:3.11 - -ARG USERNAME=c8yuser -ARG C8Y_VERSION=1.3.0 - -RUN apk update \ - && apk add curl unzip zsh git vim jq \ - && adduser -S $USERNAME \ - && mkdir -p /sessions \ - && chown $USERNAME /sessions - -USER $USERNAME -WORKDIR /home/$USERNAME - -RUN sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)" - -# add binary to path -ENV PATH=${PATH}:/home/$USERNAME/bin -ENV C8Y_SESSION_HOME=/sessions - -COPY ./c8y.linux /home/$USERNAME/bin/c8y - -# -# install c8y zsh plugin -COPY ./c8y.plugin.zsh /home/$USERNAME/.oh-my-zsh/custom/plugins/c8y/ -RUN sed -iE 's/plugins=(\(.*\))/plugins=(\1 c8y)/' ~/.zshrc \ - # - # Create completions before zsh runs otherwise - # it will not automatically load the completions until the user - # runs 'source ~/.zshrc' - && c8y completion zsh > /home/$USERNAME/.oh-my-zsh/custom/plugins/c8y/_c8y - -# Working settings -RUN chown $USERNAME /home/$USERNAME - -# Prevent zsh plugins from affecting completions -# https://github.com/ohmyzsh/ohmyzsh/issues/1282 -# https://stackoverflow.com/questions/11916064/zsh-tab-completion-duplicating-command-name -ENV LANG=C.UTF-8 -ENV LC_ALL=C.UTF-8 - -VOLUME [ "/sessions" ] - -ENTRYPOINT [ "/bin/zsh" ] diff --git a/docs/_docs/1-docker-usage.md b/docs/_docs/1-docker-usage.md index c28bfcc99..1ae80de85 100644 --- a/docs/_docs/1-docker-usage.md +++ b/docs/_docs/1-docker-usage.md @@ -22,19 +22,17 @@ The session persistence is achieved by mounting a docker volume to your host ope It is recommended that you run these commands from your home folder, so that the `~/.cumulocity` folder will be used to store the sessions, as this is the default folder that is used should you install the c8y cli tool on your host machine later on. That way you will you be able to continue using -#### bash + +#### zsh/bash/fish ```sh cd ~ -docker run -it -v $PWD/.cumulocity:/sessions --rm ghcr.io/reubenmiller/c8y-bash:latest +docker run -it -v $PWD/.cumulocity:/sessions --rm ghcr.io/reubenmiller/c8y-shell:latest ``` -#### zsh +**Note** -```sh -cd ~ -docker run -it -v $PWD/.cumulocity:/sessions --rm ghcr.io/reubenmiller/c8y-zsh:latest -``` +ZSH will start by default, however you can load another shell manuall using `bash` or `fish`. #### PowerShell (pwsh) @@ -63,7 +61,7 @@ You can provide the session information via environment variables, deviced in a 2. Start the docker container ```sh - docker run --rm -it --env-file=session.env ghcr.io/reubenmiller/c8y-zsh:latest + docker run --rm -it --env-file=session.env ghcr.io/reubenmiller/c8y-shell:latest ``` The `--env-file` argument will direct docker to map the file contents to environment variables within the container. @@ -124,7 +122,7 @@ If you have already activated a c8y session on a command console, you can re-use -e C8Y_TENANT=$C8Y_TENANT \ -e C8Y_USER=$C8Y_USER \ -e C8Y_PASSWORD=$C8Y_PASSWORD \ - ghcr.io/reubenmiller/c8y-zsh:latest + ghcr.io/reubenmiller/c8y-shell:latest ``` **PowerShell** @@ -135,19 +133,19 @@ If you have already activated a c8y session on a command console, you can re-use -e C8Y_TENANT=$env:C8Y_TENANT ` -e C8Y_USER=$env:C8Y_USER ` -e C8Y_PASSWORD=$env:C8Y_PASSWORD ` - ghcr.io/reubenmiller/c8y-zsh:latest + ghcr.io/reubenmiller/c8y-shell:latest ``` **Note** You have to execute a docker pull if you want to re-check if there is a newer image available (i.e. also tagged with latest). -You can also specify the version that you want to try out by replacing `latest` with the version number, i.e. `1.7.3`. +You can also specify the version that you want to try out by replacing `latest` with the version number, i.e. `2.0.0`. ```sh # update to the latest image -docker pull ghcr.io/reubenmiller/c8y-zsh:latest +docker pull ghcr.io/reubenmiller/c8y-shell:latest # use a known version -docker pull ghcr.io/reubenmiller/c8y-zsh:1.7.3 +docker pull ghcr.io/reubenmiller/c8y-shell:2.0.0 ``` \ No newline at end of file diff --git a/scripts/publish-docker.sh b/scripts/publish-docker.sh index 7b73b5250..bde02f1d3 100755 --- a/scripts/publish-docker.sh +++ b/scripts/publish-docker.sh @@ -38,11 +38,16 @@ publish_ghcr_docker () { login_ghcr -publish_ghcr_docker c8y-bash $VERSION -publish_ghcr_docker c8y-zsh $VERSION +publish_ghcr_docker c8y-shell $VERSION publish_ghcr_docker c8y-pwsh $VERSION -# also use latest tag -publish_ghcr_docker c8y-bash latest -publish_ghcr_docker c8y-zsh latest -publish_ghcr_docker c8y-pwsh latest +# also use latest (or next) tag +if [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + # official release + publish_ghcr_docker c8y-shell latest + publish_ghcr_docker c8y-pwsh latest +else + # beta release + publish_ghcr_docker c8y-shell next + publish_ghcr_docker c8y-pwsh next +fi