Skip to content

Commit

Permalink
support java plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
clofresh committed Dec 19, 2018
1 parent 32d0ccc commit 36bed88
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,11 @@
rundeck/libext
ssh/authorized_keys
tools

.gradle
.idea
.project
/rundeck-plugins/*/build
/rundeck-plugins/*/gradle
/rundeck-plugins/*/gradlew
/rundeck-plugins/*/gradlew.bat
55 changes: 44 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,21 @@ export RD_ENABLE_PLUGINS ?= true
PLUGINS_SRC_DIR := rundeck-plugins
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)
RD_SCRIPT_PLUGINS_STATE = $(shell find $(PLUGINS_SRC_DIR) -maxdepth 2 -type f -name plugin.yaml \
| sed 's@$(PLUGINS_SRC_DIR)/\([^/]*\)/plugin.yaml@$(RD_MAKE_STATE_DIR)/\1.scriptplugin@g')
RD_JAVA_PLUGINS_STATE = $(shell find $(PLUGINS_SRC_DIR)/ -type f -name *.java | cut -d / -f 1-2 | sort -u | sed 's@$(PLUGINS_SRC_DIR)/\(.*\)@$(RD_MAKE_STATE_DIR)/\1.javaplugin@g')
RD_PLUGIN_STATE = $(RD_SCRIPT_PLUGINS_STATE) $(RD_JAVA_PLUGINS_STATE)

# Rundeck container
SSH_AUTHORIZED_KEYS := ssh/authorized_keys

# Makes sure the ssh containers authorize the Rundeck server's public key
$(SSH_AUTHORIZED_KEYS): $(RUNDECK_IMAGE_DIR)/ssh/rundeck-playground.pub
cp $< $@
@cp $< $@

# Runs docker-compose to spin up the full environment
compose: $(SSH_AUTHORIZED_KEYS)
@echo "====[docker-compose] Starting up rundeck-playground docker environment"
docker-compose up --build

# Installs the plugins into the Rundeck container's plugin directory
Expand All @@ -44,14 +48,17 @@ plugins: $(RD_MAKE_STATE_DIR)/install-plugins
RD_PLUGIN_INSTALLED_STATE := $(RD_MAKE_STATE_DIR)/install-plugins

$(RD_PLUGIN_INSTALLED_STATE): $(RD_PLUGIN_STATE) $(RD)
for id in $$($(RD) plugins list | cut -d ' ' -f 1); do \
@IFS=$$'\n'; for line in $$($(RD) plugins list); do \
id=$$(echo $$line | cut -d ' ' -f 1); \
echo "====[Install plugins] Installing $$line"; \
$(RD) plugins install --id "$$id"; \
done && touch $@

$(RD_MAKE_STATE_DIR)/%.plugin: $(PLUGIN_OUTPUT_DIR)/%.zip $(RD)
NEW_VERSION="$$(unzip -p "$<" | grep ^version | cut -d : -f 2)"; \
$(RD_MAKE_STATE_DIR)/%.scriptplugin: $(PLUGIN_OUTPUT_DIR)/%.zip $(RD)
@NEW_VERSION="$$(unzip -p "$<" | grep ^version | cut -d : -f 2)"; \
OLD_VERSION="$$(cat "$@" 2>/dev/null || echo '0')"; \
if [[ $$NEW_VERSION -eq $$OLD_VERSION ]]; then \
echo "====[$* script plugin] ERROR: Version $$NEW_VERSION already exists. Update plugin version in $(PLUGINS_SRC_DIR)/$*/plugin.yaml"; \
echo "Version already exists for $<"; \
exit 1; \
else \
Expand Down Expand Up @@ -83,7 +90,7 @@ RD_KEYS_STATES = $(shell cd $(RD_KEYS_DIR) && \
$(RD_MAKE_STATE_DIR)/%.key: $(RD_KEYS_DIR)/% $(RD)
$(RD) keys create -t password -f $< --path $* \
|| $(RD) keys update -t password -f $< --path $*
mkdir -p $$(dirname $@) && touch $@
@mkdir -p $$(dirname $@) && touch $@

# Installs the secrets into the Rundeck Key Storage
keys: $(RD_KEYS_STATES)
Expand All @@ -93,12 +100,14 @@ PLUGIN_BOOTSTRAP := tools/rundeck-plugin-bootstrap-0.1.0-SNAPSHOT/bin/rundeck-pl
tools: $(RD) $(PLUGIN_BOOTSTRAP)

$(PLUGIN_BOOTSTRAP):
docker-compose up --build rundeck-plugin-bootstrap
docker cp rundeck-playground_rundeck-plugin-bootstrap_1:/root/tools/ .
@echo "====[rundeck-plugin-bootstrap] Installing"
@docker-compose up --build rundeck-plugin-bootstrap
@docker cp rundeck-playground_rundeck-plugin-bootstrap_1:/root/tools/ .

$(RD):
docker-compose up --build rundeck-cli
docker cp rundeck-playground_rundeck-cli_1:/root/tools/ .
@echo "====[rd] Installing"
@docker-compose up --build rundeck-cli
@docker cp rundeck-playground_rundeck-cli_1:/root/tools/ .

env:
@echo 'export RD_URL="$(RD_URL)";'
Expand Down Expand Up @@ -131,21 +140,45 @@ clean-plugins:

# Clears all the docker images, containers, network and volumes
clean-docker:
@echo "====[clean] rundeck-playground docker environment"
docker-compose down --rmi all -v

clean-rundeck:
@echo "====[clean] rundeck docker state"
docker-compose rm -sfv rundeck || true
docker volume rm rundeck-playground_rundeck-data || true
docker-compose up -d rundeck
make clean-makestate

clean-tools:
@echo "====[clean] local tools"
rm -rf tools/*

# Don't confuse these recipes with files
.PHONY: default compose plugin rd-config rd-run-job update-web keys clean clean-makestate clean-plugins clean-docker clean-rundeck clean-tools tools

# Java plugins

$(PLUGINS_SRC_DIR)/%/gradlew: rundeck-plugins/%/build.gradle
@echo "====[$* Java plugin] Making sure gradle wrapper is up to date"
@cd $(PLUGINS_SRC_DIR)/$* && gradle wrapper && touch gradlew

# Some make hackery to create a general rule for compiling plugin zips in PLUGINS_SRC_DIR
.SECONDEXPANSION:
$(PLUGIN_OUTPUT_DIR)/%.zip: $$(shell find $(PLUGINS_SRC_DIR)/%/ -type f)
mkdir -p $$(dirname $@) && cd $(PLUGINS_SRC_DIR) && zip -r ../$@ $*
@echo "====[$* script plugin] Source files changed: $?"
@mkdir -p $$(dirname $@) && cd $(PLUGINS_SRC_DIR) && zip --quiet -r ../$@ $*

$(RD_MAKE_STATE_DIR)/%.javaplugin: $(PLUGINS_SRC_DIR)/%/gradlew $(PLUGINS_SRC_DIR)/%/build.gradle $$(shell find $(PLUGINS_SRC_DIR)/%/src/ -type f -name '*.java') $(RD)
@echo "====[$* Java plugin] Source files changed: $?"
@cd $(PLUGINS_SRC_DIR)/$* && \
./gradlew build && \
JARFILE=$$(ls build/libs/$*-*.jar | sort -V | tail -n 1) && \
NEW_VERSION=$$(echo $$(basename $${JARFILE%.jar}) | cut -d - -f 2) && \
OLD_VERSION="$$(cat "$(PWD)/$@" 2>/dev/null || echo '0')" && \
if [[ $$NEW_VERSION == $$OLD_VERSION ]]; then \
echo "====[$* Java plugin] ERROR: Version $$NEW_VERSION already exists. Update plugin version in $(PLUGINS_SRC_DIR)/$*/build.gradle"; \
exit 1; \
else \
$(PWD)/$(RD) plugins upload -f "$$JARFILE" && echo "$$NEW_VERSION" > $(PWD)/$@ && rm -f $(PWD)/$(RD_PLUGIN_INSTALLED_STATE); \
fi
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
build:
context: rundeck-cli
args:
COMMIT: 6aeb65b9085c1d5811163a25c15fe278d34fd846
COMMIT: f20b69dc8e43462bf71a78dcb549997c86a51995
image: playground-rundeck-cli

# plugin bootstrap tool
Expand All @@ -22,7 +22,7 @@ services:
build:
context: rundeck-plugin-bootstrap
args:
COMMIT: 3b5783ec795386d70d52f30f5581466d76aa10b6
COMMIT: c3ebc59c35eb824d359c04370127aff4e64e6d70
image: playground-rundeck-plugin-bootstrap

# backend
Expand Down

0 comments on commit 36bed88

Please sign in to comment.