Search…
Docker
DCli is designed to work with Docker.
DCli has a Docker image you can use directly or use in a Docker 'from' statement.
You can also add DCli to an existing Dockerfile.

Adding DCli to your Dockerfile

You can add DCli to your own Dockerfile. This will allow you to run DCli scripts as part of the Docker deployment process as well as running DCli scripts within the final docker container.
DCli is installed into the root user (as is normal for a Docker container). Installers exist for Linux, Windows and Mac OSX.
Just change the wget path to obtain the correct installer:
Linux path
1
RUN apt-get -y update
2
RUN apt-get install --no-install-recommends -y wget ca-certificates gnupg2 procps
3
RUN wget https://github.com/noojee/dcli/releases/download/latest.linux/dcli_install
4
RUN chmod +x dcli_install
5
ENV PATH="${PATH}":/usr/lib/dart/bin:"${HOME}/.pub-cache/bin":"${HOME}/.dcli/bin"
6
RUN ./dcli_install
Copied!
1
RUN apt-get -y update
2
RUN apt-get install --no-install-recommends -y wget ca-certificates gnupg2 procps
3
RUN wget https://github.com/noojee/dcli/releases/download/latest-linux/dcli_install
4
RUN chmod +x dcli_install
5
ENV PATH="${PATH}":/usr/lib/dart/bin:"${HOME}/.pub-cache/bin":"${HOME}/.dcli/bin"
6
RUN ./dcli_install
Copied!
Windows path:
1
RUN wget wget https://github.com/noojee/dcli/releases/download/latest.windows/dcli_install.exe
2
# TODO correct this path
3
ENV PATH="${PATH}":/usr/lib/dart/bin:"${HOME}/.pub-cache/bin":"${HOME}/.dcli/bin"
4
RUN ./dcli_install.exe
5
Copied!
1
RUN wget wget https://github.com/noojee/dcli/releases/download/latest-linux/dcli_install.exe
2
# TODO correct this path
3
ENV PATH="${PATH}":/usr/lib/dart/bin:"${HOME}/.pub-cache/bin":"${HOME}/.dcli/bin"
4
RUN ./dcli_install.exe
Copied!
Mac OSX path:
1
RUN wget wget https://github.com/noojee/dcli/releases/download/latest.osx/dcli_install -O dcli_install
2
RUN chmod +x dcli_install
3
# TODO correct this path
4
ENV PATH="${PATH}":/usr/lib/dart/bin:"${HOME}/.pub-cache/bin":"${HOME}/.dcli/bin"
5
RUN ./dcli_install
6
Copied!
1
RUN wget wget https://github.com/noojee/dcli/releases/download/latest-osx/dcli_install -O dcli_install
2
RUN chmod +x dcli_install
3
# TODO correct this path
4
ENV PATH="${PATH}":/usr/lib/dart/bin:"${HOME}/.pub-cache/bin":"${HOME}/.dcli/bin"
5
RUN ./dcli_install
Copied!

Compiling a dart package

Now you have dart and dcli in your container you will want to import a project and compile it.
1
# now lets compile a script.
2
RUN mkdir -p /build/bin
3
RUN mkdir -p /build/lib
4
COPY pubspec.yaml /build
5
COPY bin /build/bin/
6
COPY lib /build/lib/
7
# The --install option adds the compiled script to your path.
8
dcli compile --install bin/<your script>
Copied!

Upgrading DCli in your docker image.

After building your docker image you may need to force an upgrade of the DCli version.
You can simply recreate your docker image or to save time you can just up use this one trick (sorry) to force docker to just rebuild the DCli install (and subsequent steps in your docker file).
Add the following line just before the call to wget.
If you want to force an upgrade of DCli just increment the no. and run docker build.
1
ARG PULL_LATEST_DSHELL_INSTALL=1
Copied!

Using the DCli docker image

A Docker image is available which can be used to create a DCli CLI on your system without polluting your OS.
The docker container presents a CLI with dart and DCli pre-installed so you can experiment with DCli or deploy DCli to system instances.
To use the container:
Create a volume so that your scripts are persistent:
1
docker volume create dcli_scripts
Copied!
Attach to the DCli cli.
1
docker run -v dcli_scripts:/home/scripts --network host -it dclifordart/dcli /bin/bash
2
bash:/> cd /home/scripts
3
bash:/home/scripts> dcli create hellow.dart
Copied!
The volume is mounted to /home/scripts within your dcli container.
vi is included in the container.
Alternatively you can install and run dcli directly from your cli.

git based dependencies

dart allows you to include dependencies which are pulled from a git repo.
e.g.
1
dependencies:
2
gcloud_lib:
3
git:
4
url: [email protected]:myrepo/gcloud_lib.git
5
path: gcloud_lib
Copied!
If your git repository is public then you don't need to do anything special.
If your git repository is private then calling pub get or attempting a dcli compile will fail with an auth error.
If this is your scenario then you may need to make your .ssh keys available to the docker build.
This blog article provide a details on how to achieve this.
The shorter summary is:
1
var repo = 'yourdockerrepo';
2
var image = 'yourimage';
3
var version = '1.0.0';
4
setEnv('DOCKER_BUILDKIT', '1');
5
'docker build --ssh default -t $repo/$image:$version .'.run;
Copied!
With in your docker file your FIRST line MUST be:
1
# syntax=docker/dockerfile:1.0.0-experimental
2
...
3
4
RUN apt-get update
5
RUN apt-get install --no-install-recommends -y openssh-client
6
7
# do you dcli install stuff here
8
9
ENV GIT_REP=github.org
10
# Give git access to your ssh keays
11
RUN mkdir -m 700 /root/.ssh;
12
RUN touch -m 600 /root/.ssh/known_hosts;
13
RUN ssh-keyscan $GIT_REPO > /root/.ssh/known_hosts
14
15
RUN --mount=type=ssh dcli compile bin/cmd_dispatcher.dart -o /home/build/target/cmd_dispatcher
Copied!

Alpine

If you are using an Alpine based Docker image then you will need to install gclibc.
WARNING: There appear to be some issues around using alpine. I'm seeing network errors (error 69) running pub get. These generally happen toward the end of the process but occur about 80% of the time. You can reproduce them easily by running pub cache repair. My suspicion is that its because we are installing glibc when alpine uses mu libc.
1
ENV GLIBC_VERSION 2.31-r0
2
3
# Download and install glibc
4
RUN apk add --update curl && \
5
curl -Lo /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && \
6
curl -Lo glibc.apk "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-${GLIBC_VERSION}.apk" && \
7
curl -Lo glibc-bin.apk "https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VERSION}/glibc-bin-${GLIBC_VERSION}.apk" && \
8
apk add glibc-bin.apk glibc.apk && \
9
/usr/glibc-compat/sbin/ldconfig /lib /usr/glibc-compat/lib && \
10
echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' >> /etc/nsswitch.conf && \
11
apk del curl && \
12
rm -rf glibc.apk glibc-bin.apk /var/cache/apk/*
13
14
# dcli requires ps command
15
RUN apk add --update procps
16
RUN apk add --update wget
17
18
# pub requires bash and tar
19
RUN apk add bash
20
RUN apk add tar
21
22
RUN wget https://github.com/noojee/dcli/raw/master/bin/linux/dcli_install
23
RUN chmod +x dcli_install
24
RUN ./dcli_install
25
ENV PATH="${PATH}:/usr/bin/dart/bin:/root/.pub-cache/bin"
Copied!
Last modified 1mo ago