Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from pennsignals/deploy_config
Browse files Browse the repository at this point in the history
Deploy config
  • Loading branch information
darrylmendillo authored Dec 3, 2020
2 parents ee6463f + 89c9e9f commit 8de7754
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 48 deletions.
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
24 changes: 4 additions & 20 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
14 changes: 7 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 19 additions & 12 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
done
10 changes: 5 additions & 5 deletions src/submit_to_consul.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 8de7754

Please sign in to comment.