From c60c1d1638ffa8b56c96479a883a8c0967b2b808 Mon Sep 17 00:00:00 2001 From: Darryl Mendillo <1238655+darrylmendillo@users.noreply.github.com> Date: Thu, 3 Dec 2020 15:13:19 -0500 Subject: [PATCH 1/4] replace inputs with config file --- Dockerfile | 10 +++++++++- action.yml | 24 ++++-------------------- entrypoint.sh | 31 +++++++++++++++++++------------ 3 files changed, 32 insertions(+), 33 deletions(-) diff --git a/Dockerfile b/Dockerfile index d1191fc..7cc75eb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,18 @@ FROM debian:10.6-slim +ARG VERSION="3.4.1" +ARG BINARY="yq_linux_amd64" + RUN apt-get update && \ apt-get install -y \ - curl + curl \ + wget ADD entrypoint.sh /entrypoint.sh ADD ./src/submit_to_consul.sh /scripts/submit_to_consul.sh +# install yq +RUN wget https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY} -O /usr/bin/yq &&\ + chmod +x /usr/bin/yq + ENTRYPOINT [ "/entrypoint.sh" ] \ No newline at end of file diff --git a/action.yml b/action.yml index 57b1f62..23177d1 100644 --- a/action.yml +++ b/action.yml @@ -9,29 +9,13 @@ inputs: addr: description: "The HTTP address for Consul" required: true - path: - description: "Path to submit files in Consul. Do not include deploy environment (staging/production). Format: path/to/key Default to \"\"." - required: false - default: "" - regex: - description: "Regex for files to submit" - required: true - locations: - description: "Search locations for config files. Defaults to GITHUB_WORKSPACE" - default: "./" - required: false - service: - description: "Service name. Config files are stored in service" + config: + description: "deploy_config.yml file with all deployment settings" required: true - deploy: - description: "Deployment environent. Submits only configs matching environment, and renames them. Example (staging.yaml -> config.yaml) Defaults to staging" - default: "staging" - required: false + runs: using: "docker" image: "Dockerfile" args: - ${{ inputs.addr }} - - ${{ inputs.path }} - - ${{ inputs.regex }} - - ${{ inputs.location }} + - ${{ inputs.config }} diff --git a/entrypoint.sh b/entrypoint.sh index f2e4ac6..a59a606 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,21 +2,28 @@ # echo all the variabls echo "INPUT_ADDR: $INPUT_ADDR" -echo "INPUT_PATH: $INPUT_PATH" -echo "INPUT_REGEX: $INPUT_REGEX" -echo "INPUT_LOCATIONS: $INPUT_LOCATIONS" -echo "INPUT_DEPLOY: $INPUT_DEPLOY" +echo "INPUT_CONFIG: $INPUT_CONFIG" -# go through each Search Location -echo "Searching: $INPUT_LOCATIONS" -for INPUT_LOCATION in $(echo $INPUT_LOCATIONS | sed "s/,/ /g"); do +DEPLOY_CONFIG="$INPUT_CONFIG" +# parse DEPLOY_CONFIG file and build VAULT_PATH +DEPLOY=$(yq read $DEPLOY_CONFIG 'deploy') +CONSUL_PATH=$(yq read $DEPLOY_CONFIG 'organization')/$(yq read $DEPLOY_CONFIG 'project') +SERVICES=$(yq read --printMode p $DEPLOY_CONFIG 'services.*.' | cut -f2 -d '.') +REGEX=$(yq read $DEPLOY_CONFIG 'template.configs.regex') - # find all files in subdirectories of location - CONFIG_FILES=$(find "${INPUT_LOCATION}" -type f -regextype posix-extended -regex "${INPUT_REGEX}") +# go through each SERVICE +for SERVICE in $(echo $SERVICES | sed "s/,/ /g"); do + echo "Service: $SERVICE" + + # build CONSUL PATH + CONFIGS_PATH=$(yq read $DEPLOY_CONFIG services.$SERVICE.location)/$(yq read $DEPLOY_CONFIG template.configs.location) + + # find all config files matching regex file extension and deploy environement (example staging.yml) + CONFIG_FILES=$(find "${CONFIGS_PATH}" -type f -regextype posix-extended -regex "${REGEX}" -and -regex ".*.${DEPLOY}.*") # submit all found config files to consul - echo "/scripts/submit_to_consul.sh --path ${INPUT_PATH} --address ${INPUT_ADDR} --deploy ${INPUT_DEPLOY} --service "${INPUT_SERVICE}" ${CONFIG_FILES}" - /scripts/submit_to_consul.sh --path "${INPUT_PATH}" --address "${INPUT_ADDR}" --deploy "${INPUT_DEPLOY}" --service "${INPUT_SERVICE}" "${CONFIG_FILES}" + echo "/scripts/submit_to_consul.sh --path ${CONSUL_PATH} --address ${INPUT_ADDR} --deploy ${DEPLOY} --service "${SERVICE}" ${CONFIG_FILES}" + /scripts/submit_to_consul.sh --path "${CONSUL_PATH}" --address "${INPUT_ADDR}" --deploy "${DEPLOY}" --service "${SERVICE}" "${CONFIG_FILES}" -done \ No newline at end of file +done From 7a2f866c37826abcafb3c041530381660ac7bfb5 Mon Sep 17 00:00:00 2001 From: Darryl Mendillo <1238655+darrylmendillo@users.noreply.github.com> Date: Thu, 3 Dec 2020 15:13:43 -0500 Subject: [PATCH 2/4] move deploy env regex to entrypoint --- src/submit_to_consul.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/submit_to_consul.sh b/src/submit_to_consul.sh index d33b086..2c3c2ff 100755 --- a/src/submit_to_consul.sh +++ b/src/submit_to_consul.sh @@ -41,13 +41,13 @@ get_all_configs() { echo local f - # check each file for regex (matching deploy env) + + # send each config to put_config echo "looking for *.$DEPLOY" for f; do - case "$f" in - *.${DEPLOY}.*) echo "$0: uploading $f"; put_config "$ADDRESS" "$CONSUL_PATH" "$DEPLOY" "$SERVICE" "$f"; echo ;; - *) echo "$0: ignoring $f" ;; - esac + echo "$0: uploading $f" + put_config "$ADDRESS" "$CONSUL_PATH" "$DEPLOY" "$SERVICE" "$f" + echo done } From 1c6fb9b27a246c2e46ee0c2f69f103a28e025f04 Mon Sep 17 00:00:00 2001 From: Darryl Mendillo <1238655+darrylmendillo@users.noreply.github.com> Date: Thu, 3 Dec 2020 15:44:21 -0500 Subject: [PATCH 3/4] update readme --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f3d5c70..8e7ec79 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,6 @@ Searches all subdirectories of `location` using `regex` expression. All matched uses: pennsignals/consul_configs_submit_action@main with: addr: 'http://10.146.0.5:8500/v1/kv' # required - regex: '^.*.(yaml|yml|conf|json)$' # required - location: "./project/local" # optional (default = "./") - path: "organization/project/tag" # optional (default = "") + config: './deploy_config.yml' # required + ``` \ No newline at end of file From 89c9e9f1eceec08dc980bfd0ac9c41ed085375eb Mon Sep 17 00:00:00 2001 From: Darryl Mendillo <1238655+darrylmendillo@users.noreply.github.com> Date: Thu, 3 Dec 2020 15:44:39 -0500 Subject: [PATCH 4/4] update docker-compose --- docker-compose.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index b5e8fdf..b4b1c89 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,16 +2,16 @@ version: "3.8" services: - submit: - build: - context: . + consul: + build: . + entrypoint: /bin/bash environment: - INPUT_ADDR=http://10.146.0.5:8500/v1/kv - - INPUT_PATH=pennsignals/ - - INPUT_REGEX="" - - INPUT_LOCATION=./epic/local - - INPUT_DEPLOY=staging + - INPUT_CONFIG=deploy_config.yml restart: always stdin_open: true # docker run -i stop_signal: SIGTERM tty: true # docker run -t + volumes: + - ./:/source/ + working_dir: /source \ No newline at end of file