Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage username and password with Docker Secrets #5

Merged
merged 2 commits into from
Apr 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ LABEL org.label-schema.vendor="vfarcic" \
org.label-schema.schema-version="1.0" \
org.label-schema.build-date=$build_date

ENV "SWARM_CLIENT_VERSION=2.2" \
ENV "SWARM_CLIENT_VERSION=3.3" \
"DOCKER_COMPOSE_VERSION=1.11.2" \
"COMMAND_OPTIONS="
"COMMAND_OPTIONS=" \
"USER_NAME_SECRET=" \
"PASSWORD_SECRET="

RUN adduser -G root -D jenkins \
&& apk --update --no-cache add openjdk8-jre python py-pip git openssh \
&& wget -q https://repo.jenkins-ci.org/releases/org/jenkins-ci/plugins/swarm-client/${SWARM_CLIENT_VERSION}/swarm-client-${SWARM_CLIENT_VERSION}-jar-with-dependencies.jar -P /home/jenkins/ \
&& wget -q https://repo.jenkins-ci.org/releases/org/jenkins-ci/plugins/swarm-client/${SWARM_CLIENT_VERSION}/swarm-client-${SWARM_CLIENT_VERSION}.jar -P /home/jenkins/ \
&& pip install docker-compose

COPY run.sh /run.sh
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,22 @@ Usage
-----

The environment variable COMMAND_OPTIONS has to be specified with non-empty value, which is a combination of all swarm client options you need. Please refer to this [Swarm Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Swarm+Plugin) for all available options.

For the username and password, it makes use of [Docker Secrets](https://docs.docker.com/engine/swarm/secrets/).
You can run this service as follows:

```bash
docker service create --name $JENKINS_AGENT_SERVICE \
--secret source=jenkins-master1-usr,target=jks-admin-usr \
--secret source=jenkins-master1-pass,target=jks-admin-pass \
-e USER_NAME_SECRET="/run/secrets/jks-admin-usr"\
-e PASSWORD_SECRET="/run/secrets/jks-admin-pass"\
-e COMMAND_OPTIONS="-master http://${MASTER_URL}:8080 \
-labels 'docker' -executors 3
-fsroot /tmp" \
--network $NETWORK \
--mode global \
--mount "type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock" \
--mount "type=bind,source=/tmp,target=/tmp/workspace" \
vfarcic/jenkins-swarm-agent
```
4 changes: 3 additions & 1 deletion run.sh
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
java -jar /home/jenkins/swarm-client-${SWARM_CLIENT_VERSION}-jar-with-dependencies.jar ${COMMAND_OPTIONS}
read PSS < ${PASSWORD_SECRET}
read USR < ${USER_NAME_SECRET}
java -jar /home/jenkins/swarm-client-${SWARM_CLIENT_VERSION}.jar ${COMMAND_OPTIONS} -username $USR -password $PSS