From d9c2e0afe6a271ff34a3c9eba55df24944a64802 Mon Sep 17 00:00:00 2001
From: Darryl Mendillo <1238655+darrylmendillo@users.noreply.github.com>
Date: Wed, 31 Mar 2021 14:12:52 -0400
Subject: [PATCH 1/4] use consul CLI instead of API
---
Dockerfile | 19 ++++++--
action.yml | 3 +-
docker-compose.yml | 9 ++--
entrypoint.sh | 28 +++++------
src/submit_to_consul.sh | 101 ----------------------------------------
5 files changed, 33 insertions(+), 127 deletions(-)
delete mode 100755 src/submit_to_consul.sh
diff --git a/Dockerfile b/Dockerfile
index 276af6b..472e1bf 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,19 +1,30 @@
+ARG CONSUL_VERSION=1.8.5
+ARG YQ_VERSION=3.4.1
+ARG BINARY=linux_amd64
+
FROM debian:10.6-slim as consul
+
LABEL name=consul
-ARG VERSION="3.4.1"
-ARG BINARY="yq_linux_amd64"
+ARG CONSUL_VERSION
+ARG YQ_VERSION
+ARG BINARY
RUN apt-get update && \
apt-get install -y \
curl \
- wget
+ wget \
+ unzip
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 &&\
+RUN wget -qO /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_${BINARY} &&\
chmod +x /usr/bin/yq
+# install consul
+RUN wget -qO consul.zip https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_${BINARY}.zip &&\
+ unzip consul.zip -d /usr/local/bin/
+
ENTRYPOINT [ "/entrypoint.sh" ]
\ No newline at end of file
diff --git a/action.yml b/action.yml
index dd0ce31..870bd19 100644
--- a/action.yml
+++ b/action.yml
@@ -15,11 +15,12 @@ inputs:
env:
description: "Deployment environment ot override deploy_config.yml. ex: staging, production"
required: false
+ default: 'staging'
runs:
using: "docker"
image: "Dockerfile"
env:
- CONSUL_ADDR: ${{ inputs.addr }}
+ CONSUL_HTTP_ADDR: ${{ inputs.addr }}
DEPLOY_CONFIG: ${{ inputs.config }}
ENV: ${{ inputs.env }}
\ No newline at end of file
diff --git a/docker-compose.yml b/docker-compose.yml
index b4b1c89..ddedb0b 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -6,12 +6,13 @@ services:
build: .
entrypoint: /bin/bash
environment:
- - INPUT_ADDR=http://10.146.0.5:8500/v1/kv
- - INPUT_CONFIG=deploy_config.yml
+ CONSUL_HTTP_ADDR: "http://10.145.240.242:8500"
+ DEPLOY_CONFIG: "local/deploy_config.yml"
+ ENV: "staging"
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
+ - /Users/dmendillo/Documents/GitHub/palliativeconnect:/source/
+ working_dir: /source
diff --git a/entrypoint.sh b/entrypoint.sh
index 05aea2f..1507821 100755
--- a/entrypoint.sh
+++ b/entrypoint.sh
@@ -1,32 +1,26 @@
#!/bin/sh
# echo all the variabls
-echo "CONSUL_ADDR: $CONSUL_ADDR"
+echo "CONSUL_HTTP_ADDR: $CONSUL_HTTP_ADDR"
echo "DEPLOY_CONFIG: $DEPLOY_CONFIG"
echo "ENV: $ENV"
-# parse DEPLOY_CONFIG file and build VAULT_PATH
-
-# Use input environment parameter if given
-CONFIG_ENV=$(yq read $DEPLOY_CONFIG 'deploy')
-DEPLOY="$ENV:-$CONFIG_ENV"
-
-CONSUL_PATH=$(yq read $DEPLOY_CONFIG 'organization')/$(yq read $DEPLOY_CONFIG 'project')
+# parse DEPLOY_CONFIG file and build PATH
+ORGANIZATION=$(yq read $DEPLOY_CONFIG 'organization')
+PROJECT=$(yq read $DEPLOY_CONFIG 'project')
SERVICES=$(yq read --printMode p $DEPLOY_CONFIG 'services.*.' | cut -f2 -d '.')
-REGEX=$(yq read $DEPLOY_CONFIG 'template.configs.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}.*")
+ # get file based on environenment (staging / production)
+ CONFIG_FILE=$(yq read $DEPLOY_CONFIG services.$SERVICE.location)/$(yq read $DEPLOY_CONFIG template.configs.location)/$(yq read $DEPLOY_CONFIG services.$SERVICE.configuration.local.$ENV)
+
+ # set filename to .configuration.name
+ FILE_NAME=$(yq read $DEPLOY_CONFIG services.$SERVICE.configuration.name)
- # submit all found config files to consul
- echo "/scripts/submit_to_consul.sh --path ${CONSUL_PATH} --address ${CONSUL_ADDR} --deploy ${DEPLOY} --service "${SERVICE}" ${CONFIG_FILES}"
- /scripts/submit_to_consul.sh --path "${CONSUL_PATH}" --address "${CONSUL_ADDR}" --deploy "${DEPLOY}" --service "${SERVICE}" "${CONFIG_FILES}"
+ # submit to consul
+ consul kv put $ORGANIZATION/$PROJECT/$SERVICE/$FILE_NAME $CONFIG_FILE
done
diff --git a/src/submit_to_consul.sh b/src/submit_to_consul.sh
deleted file mode 100755
index ca28e4e..0000000
--- a/src/submit_to_consul.sh
+++ /dev/null
@@ -1,101 +0,0 @@
-#!/bin/sh
-
-# Put config file into consul kv store
-put_config() {
- ADDRESS="$1"
- CONSUL_PATH="$2"
- DEPLOY="$3"
- SERVICE="$4"
- FILE="$5"
-
- # rename file based on DEPLOY (ex sample.staging.yml -> sample.config.yml)
- FILE_NAME=$(echo ${FILE##*/} | sed 's/'"$DEPLOY"'/config/')
-
- # write config file at $CONSUL_PATH
- echo "curl -fX PUT --data-binary @$FILE $ADDRESS/$CONSUL_PATH/$SERVICE/$FILE_NAME"
- /usr/bin/curl -fX PUT --data-binary @$FILE $ADDRESS/$CONSUL_PATH/$SERVICE/$FILE_NAME
-
-}
-
-
-helpmenu() {
- echo "Usage submit_to_consul [options...]
"
- echo " -h, --h help menu"
- echo " -p, --path consul kv destination path (default: \"\")"
- echo " -a, --address consul destination address (default: \"http://10.146.0.5:8500/v1/kv\")"
- echo " -d, --deploy deployment environment (default: \"staging\")"
- echo " -s, --service service name (default: \"default\")"
-}
-
-get_all_configs() {
-
- # Get Variables then shift to start a files
- ADDRESS="$1"
- shift
- CONSUL_PATH="$1"
- shift
- DEPLOY="$1"
- shift
- SERVICE="$1"
- shift
-
- echo
- local f
-
- # send each config to put_config
- echo "looking for *.$DEPLOY"
- for f; do
- echo "$0: uploading $f"
- put_config "$ADDRESS" "$CONSUL_PATH" "$DEPLOY" "$SERVICE" "$f"
-
- echo
- done
-}
-
-_main()
-{
- # Set default values
- ADDRESS=http://10.146.0.5:8500/v1/kv
- CONSUL_PATH=/
- DEPLOY=staging
- SERVICE=default
-
- while [ ! $# -eq 0 ]
- do
- case "$1" in
- --help | -h)
- helpmenu
- exit
- ;;
- --path | -p)
- CONSUL_PATH="$2"
- shift
- ;;
- --address | -a)
- ADDRESS="$2"
- shift
- ;;
- --deploy | -d)
- DEPLOY="$2"
- shift
- ;;
- --service | -s)
- SERVICE="$2"
- shift
- ;;
- *)
- get_all_configs $ADDRESS $CONSUL_PATH $DEPLOY $SERVICE $@
- exit
- ;;
- -*)
- echo "Invalid option flag"
- helpmenu
- exit
- ;;
- esac
- shift
- done
-
- get_all_configs "$@"
-}
-_main "$@"
From e3b9d0580eae9ab6176c9bc4579b7dd7c5aec5fd Mon Sep 17 00:00:00 2001
From: Darryl Mendillo <1238655+darrylmendillo@users.noreply.github.com>
Date: Wed, 31 Mar 2021 14:19:23 -0400
Subject: [PATCH 2/4] fix consul put to add file
---
Dockerfile | 9 ++++-----
docker-compose.yml | 4 ++--
entrypoint.sh | 2 +-
3 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/Dockerfile b/Dockerfile
index 472e1bf..c6567b4 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -17,14 +17,13 @@ RUN apt-get update && \
unzip
ADD entrypoint.sh /entrypoint.sh
-ADD ./src/submit_to_consul.sh /scripts/submit_to_consul.sh
-# install yq
+# download yq and consul
RUN wget -qO /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_${BINARY} &&\
- chmod +x /usr/bin/yq
+ wget -qO consul.zip https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_${BINARY}.zip
-# install consul
-RUN wget -qO consul.zip https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_${BINARY}.zip &&\
+# install yq and consul
+RUN chmod +x /usr/bin/yq &&\
unzip consul.zip -d /usr/local/bin/
ENTRYPOINT [ "/entrypoint.sh" ]
\ No newline at end of file
diff --git a/docker-compose.yml b/docker-compose.yml
index ddedb0b..4974a43 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -4,11 +4,11 @@ services:
consul:
build: .
- entrypoint: /bin/bash
+ #entrypoint: /bin/bash
environment:
CONSUL_HTTP_ADDR: "http://10.145.240.242:8500"
DEPLOY_CONFIG: "local/deploy_config.yml"
- ENV: "staging"
+ ENV: "production"
restart: always
stdin_open: true # docker run -i
stop_signal: SIGTERM
diff --git a/entrypoint.sh b/entrypoint.sh
index 1507821..7251c79 100755
--- a/entrypoint.sh
+++ b/entrypoint.sh
@@ -21,6 +21,6 @@ for SERVICE in $(echo $SERVICES | sed "s/,/ /g"); do
FILE_NAME=$(yq read $DEPLOY_CONFIG services.$SERVICE.configuration.name)
# submit to consul
- consul kv put $ORGANIZATION/$PROJECT/$SERVICE/$FILE_NAME $CONFIG_FILE
+ consul kv put $ORGANIZATION/$PROJECT/$SERVICE/$FILE_NAME @$CONFIG_FILE
done
From 5beb886a98bc8544134fe880d4701e2a80c62371 Mon Sep 17 00:00:00 2001
From: Darryl Mendillo <1238655+darrylmendillo@users.noreply.github.com>
Date: Wed, 31 Mar 2021 15:47:20 -0400
Subject: [PATCH 3/4] download binaries to tmp
---
Dockerfile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Dockerfile b/Dockerfile
index c6567b4..159c466 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -20,10 +20,10 @@ ADD entrypoint.sh /entrypoint.sh
# download yq and consul
RUN wget -qO /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_${BINARY} &&\
- wget -qO consul.zip https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_${BINARY}.zip
+ wget -qO /tmp/consul.zip https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_${BINARY}.zip
# install yq and consul
RUN chmod +x /usr/bin/yq &&\
- unzip consul.zip -d /usr/local/bin/
+ unzip /tmp/consul.zip -d /usr/local/bin/
ENTRYPOINT [ "/entrypoint.sh" ]
\ No newline at end of file
From 22b2f33d440e89b86668a7c753ea2d8d027698ad Mon Sep 17 00:00:00 2001
From: Darryl Mendillo <1238655+darrylmendillo@users.noreply.github.com>
Date: Wed, 31 Mar 2021 15:54:46 -0400
Subject: [PATCH 4/4] update publish action
---
.github/workflows/publish.yml | 60 +++--------------------------------
1 file changed, 5 insertions(+), 55 deletions(-)
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
index 38a5607..85c415c 100644
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/publish.yml
@@ -13,60 +13,10 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v2.3.4
-
- - name: version
- run: |
- # Tagged release
- if [[ ${{ github.ref }} == refs/tags/* ]]; then
- # Strip git ref prefix from $VERSION
- TAGNAME=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
- # Strip "v" prefix from tag name
- VERSION=$(echo $TAGNAME | sed -e 's/^v//')
- else
- VERSION=${{ github.sha }}
- fi
-
- echo "VERSION=$VERSION" >> $GITHUB_ENV
- echo "GITHUB_REF=$GITHUB_REF" >> $GITHUB_ENV
-
- # write .env to export ENV VARIABLES as artifacts for use in other workflow_run runs
- echo "PUBLISH_VERSION=$VERSION" >> .env
- echo "PUBLISH_GITHUB_REF=$GITHUB_REF" >> .env
-
- echo "Version: $VERSION"
-
- export DOCKER_BUILDKIT=1
-
+
- name: publish
- run: |
- VERSION="${{ env.VERSION }}"
-
- echo ${{ secrets.GITHUB_TOKEN }} | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
-
- # build and run the docker images
- docker-compose -f docker-compose.build.yml up --no-start
-
- # get all built IDs
- IMAGE_IDs=$(docker-compose -f docker-compose.build.yml images -q)
-
- echo "IMAGE_IDs: $IMAGE_IDs"
-
- while read -r IMAGE_ID; do
-
- echo "IMAGE_ID: $IMAGE_ID"
- # get the name label
- NAME=$(basename ${{ github.repository }}).$(docker inspect --format '{{ index .Config.Labels.name }}' $IMAGE_ID)
- PUSH="docker.pkg.github.com/${{ github.repository }}/$NAME:$VERSION"
-
- # tag and push
- docker tag $IMAGE_ID $PUSH
- docker push $PUSH
-
- done <<< "$IMAGE_IDs"
-
- # Upload reference as artifact to pass to deploy
- - name: upload .env
- uses: actions/upload-artifact@v2
+ id: publish
+ uses: pennsignals/publish_docker-compose@v0.1.1
with:
- name: env
- path: .env
+ docker_compose: 'docker-compose.build.yml'
+ repo_token: "${{ secrets.GITHUB_TOKEN }}"
\ No newline at end of file