Skip to content

Commit

Permalink
Use the plugin api
Browse files Browse the repository at this point in the history
  • Loading branch information
clofresh committed Oct 17, 2018
1 parent 870e7af commit e75a1aa
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 31 deletions.
37 changes: 20 additions & 17 deletions Makefile
Expand Up @@ -12,12 +12,12 @@ NETWORK_NAME := $(CONTAINER_PREFIX)default
NUM_WEB := 2

# Command to call the Rundeck client from outside of the container
RD := docker run --network $(NETWORK_NAME) --mount type=bind,source="$$(pwd)",target=/root playground-rundeck-cli
RD := docker run --rm --network $(NETWORK_NAME) --mount type=bind,source="$$(pwd)",target=/root playground-rundeck-cli

# Plugins
PLUGINS_SRC_DIR := rundeck-plugins
LOCAL_LIBEXT_DIR := $(RUNDECK_IMAGE_DIR)/libext
PLUGINS = $(shell for p in $$(ls $(PLUGINS_SRC_DIR)); do echo "$(LOCAL_LIBEXT_DIR)/$${p}.zip"; done)
PLUGIN_OUTPUT_DIR := $(RD_MAKE_STATE_DIR)/plugins
PLUGINS = $(shell for p in $$(ls $(PLUGINS_SRC_DIR)); do echo "$(PLUGIN_OUTPUT_DIR)/$${p}.zip"; done)
RD_PLUGIN_STATE = $(shell for p in $$(ls $(PLUGINS_SRC_DIR)); do echo "$(RD_MAKE_STATE_DIR)/$${p}.plugin"; done)

# Rundeck container
Expand All @@ -30,26 +30,29 @@ $(SSH_AUTHORIZED_KEYS): $(RUNDECK_IMAGE_DIR)/ssh/rundeck-playground.pub
cp $< $@

# Runs docker-compose to spin up the full environment
compose: $(PLUGINS) $(SSH_AUTHORIZED_KEYS)
compose: $(SSH_AUTHORIZED_KEYS)
docker-compose up --build

# Installs the plugins into the Rundeck container's plugin directory
plugins: $(RD_PLUGIN_STATE)
$(RD_MAKE_STATE_DIR)/%.plugin: $(LOCAL_LIBEXT_DIR)/%.zip
docker cp $< $(RUNDECK_CONTAINER):/tmp/
docker exec -u root $(RUNDECK_CONTAINER) \
/bin/bash -c 'chown rundeck:rundeck /tmp/$$(basename $<) \
&& mv /tmp/$$(basename $<) $(RUNDECK_CONTAINER_LIBEXT)/'
touch $@
plugins: $(RD_MAKE_STATE_DIR)/install-plugins

RD_PLUGIN_INSTALLED_STATE := $(RD_MAKE_STATE_DIR)/install-plugins

$(RD_PLUGIN_INSTALLED_STATE): $(RD_PLUGIN_STATE)
for id in $$($(RD) plugins list | grep 'not installed' | cut -d ' ' -f 1); do \
$(RD) plugins install --id "$$id"; \
done && touch $@

$(RD_MAKE_STATE_DIR)/%.plugin: $(PLUGIN_OUTPUT_DIR)/%.zip
$(RD) plugins upload -f "$<" && touch $@ && rm -f $(RD_PLUGIN_INSTALLED_STATE)

# Creates the Rundeck project and sets its config properties
RD_PROJECT := hello-project
RD_PROJECT_CONFIG_DIR := rundeck-project
RD_PROJECT_STATE := $(RD_MAKE_STATE_DIR)/$(RD_PROJECT)
$(RD_PROJECT_STATE): $(RD_PROJECT_CONFIG_DIR)/project.properties
$(RD) projects create -p $(RD_PROJECT) || true
$(RD) projects configure update -p $(RD_PROJECT) --file $<
touch $@
$(RD) projects configure update -p $(RD_PROJECT) --file $< && touch $@

# Installs the Rundeck job configuration
RD_JOBS_ALL := $(RD_MAKE_STATE_DIR)/all.yaml
Expand All @@ -74,7 +77,7 @@ $(RD_MAKE_STATE_DIR)/%.key: $(RD_KEYS_DIR)/%
keys: $(RD_KEYS_STATES)

# Installs all the Rundeck config, keys and plugin
rd-config: $(RD_PLUGIN_STATE) $(RD_JOBS_ALL) $(RD_KEYS_STATES)
rd-config: $(RD_PLUGIN_INSTALLED_STATE) $(RD_JOBS_ALL) $(RD_KEYS_STATES)

# Triggers a Rundeck job
JOB ?= HelloWorld
Expand All @@ -98,7 +101,7 @@ clean-makestate:

# Clears the zipped plugins
clean-plugins:
rm -f $(RUNDECK_IMAGE_DIR)/libext/*
rm -f $(RD_PLUGIN_INSTALLED_STATE) $(RD_PLUGIN_STATE)

# Clears all the docker images, containers, network and volumes
clean-docker:
Expand All @@ -109,5 +112,5 @@ clean-docker:

# Some make hackery to create a general rule for compiling plugin zips in PLUGINS_SRC_DIR
.SECONDEXPANSION:
$(LOCAL_LIBEXT_DIR)/%-plugin.zip: $$(shell find $(PLUGINS_SRC_DIR)/%-plugin/ -type f)
cd $(PLUGINS_SRC_DIR) && zip -r ../$@ $*-plugin
$(PLUGIN_OUTPUT_DIR)/%.zip: $$(shell find $(PLUGINS_SRC_DIR)/%/ -type f)
mkdir -p $$(dirname $@) && cd $(PLUGINS_SRC_DIR) && zip -r ../$@ $*
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -52,6 +52,7 @@ You can also interact with the Rundeck server using the `rd` command line tool.

```
docker run \
--rm \
--network rundeck-playground_default \
--mount type=bind,source="$(pwd)",target=/root \
-e RD_PROJECT=hello-project \
Expand All @@ -62,7 +63,7 @@ docker run \
To avoid all that typing, you can create an alias:

```
alias rd='docker run --network rundeck-playground_default --mount type=bind,source="$(pwd)",target=/root -e RD_PROJECT=hello-project playground-rundeck-cli '
alias rd='docker run --rm --network rundeck-playground_default --mount type=bind,source="$(pwd)",target=/root -e RD_PROJECT=hello-project playground-rundeck-cli '
rd run -f --job 'HelloWorld'
```
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Expand Up @@ -42,6 +42,7 @@ services:
- "4440:4440"
volumes:
- rundeck-data:/home/rundeck/server/data
command: -Drundeck.features.repository.enabled=true

# packager host
fpm:
Expand Down
13 changes: 10 additions & 3 deletions rundeck-cli/Dockerfile
@@ -1,9 +1,16 @@
FROM openjdk:8-jre
RUN curl -sL https://github.com/rundeck/rundeck-cli/releases/download/v1.1.0-alpha/rundeck-cli_1.1.0.SNAPSHOT-1_all.deb > /rundeck-cli.deb
RUN dpkg -i /rundeck-cli.deb && rm /rundeck-cli.deb
FROM openjdk:8-jdk
RUN mkdir /tmp/rd && curl -sL https://github.com/rundeck/rundeck-cli/archive/feature/repository-commands.zip > /tmp/rd/rd.zip
RUN cd /tmp/rd/ \
&& unzip rd.zip \
&& cd rundeck-cli-feature-repository-commands \
&& ./gradlew build \
&& ls build/distributions/ \
&& dpkg -i build/distributions/*.deb \
&& rm -rf /tmp/rd
ENV RD_URL http://rundeck:4440
ENV RD_BYPASS_URL http://127.0.0.1:4440
ENV RD_USER admin
ENV RD_PASSWORD admin
ENV RD_ENABLE_PLUGINS true
WORKDIR /root
ENTRYPOINT ["/usr/bin/rd"]
@@ -1,8 +1,8 @@
name: Database credential management
version: 1
name: db creds
version: 3
rundeckPluginVersion: 1.2
author: Carlo Cabanilla
date: 2018-07-20
date: 2018-07-20T00:00:00Z
url: http://rundeck.org/
providers:
- name: RestartApp
Expand Down
@@ -1,8 +1,8 @@
name: deb builder
version: 1
version: 2
rundeckPluginVersion: 1.2
author: Carlo Cabanilla
date: 2018-09-21
date: 2018-09-21T00:00:00Z
url: http://rundeck.org/
providers:
- name: BuildDeb
Expand Down
@@ -1,8 +1,8 @@
name: Hello World
version: 1
name: helloworld
version: 5
rundeckPluginVersion: 1.2
author: Carlo Cabanilla
date: 2018-07-20
date: 2018-07-20T00:00:00Z
url: http://rundeck.org/
providers:
- name: HelloBash
Expand Down
2 changes: 1 addition & 1 deletion rundeck-project/jobs/PackageDeb.yaml
Expand Up @@ -37,7 +37,7 @@
configuration:
export: DOWNLOAD_URL
group: export
value: ${data.DOWNLOAD_URL@fpm}
value: ${data.DOWNLOAD_URL@fpm}
- type: export-var
nodeStep: false
configuration:
Expand Down
1 change: 0 additions & 1 deletion rundeck/Dockerfile
Expand Up @@ -5,4 +5,3 @@ RUN chmod 0700 /home/rundeck/.ssh \
&& chmod 0600 /home/rundeck/.ssh/* \
&& chmod 0644 /home/rundeck/.ssh/*.pub
COPY --chown=rundeck:rundeck nodes.yaml /home/rundeck/
COPY --chown=rundeck:rundeck libext/* /home/rundeck/libext/

0 comments on commit e75a1aa

Please sign in to comment.