Skip to content

Commit

Permalink
merging docker c8y bash and zsh images to one called c8y-shell which …
Browse files Browse the repository at this point in the history
…includes bash, zsh and fish
  • Loading branch information
reubenmiller committed Apr 12, 2021
1 parent d27729e commit c06bb33
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 109 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 3 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand Down
25 changes: 0 additions & 25 deletions docker/bash.dockerfile

This file was deleted.

9 changes: 6 additions & 3 deletions docker/pwsh.dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
60 changes: 60 additions & 0 deletions docker/shell.dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
44 changes: 0 additions & 44 deletions docker/zsh.dockerfile

This file was deleted.

24 changes: 11 additions & 13 deletions docs/_docs/1-docker-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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**
Expand All @@ -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
```
17 changes: 11 additions & 6 deletions scripts/publish-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c06bb33

Please sign in to comment.