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 #7 from pennsignals/add_prod_path
Browse files Browse the repository at this point in the history
Add prod path
  • Loading branch information
darrylmendillo authored Mar 31, 2021
2 parents e59a41d + 22b2f33 commit 5325dc0
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 186 deletions.
60 changes: 5 additions & 55 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
24 changes: 17 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
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 &&\
chmod +x /usr/bin/yq
# download yq and consul
RUN wget -qO /usr/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_${BINARY} &&\
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 /tmp/consul.zip -d /usr/local/bin/

ENTRYPOINT [ "/entrypoint.sh" ]
3 changes: 2 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
11 changes: 6 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ services:

consul:
build: .
entrypoint: /bin/bash
#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: "production"
restart: always
stdin_open: true # docker run -i
stop_signal: SIGTERM
tty: true # docker run -t
volumes:
- ./:/source/
working_dir: /source
- /Users/dmendillo/Documents/GitHub/palliativeconnect:/source/
working_dir: /source
28 changes: 11 additions & 17 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
101 changes: 0 additions & 101 deletions src/submit_to_consul.sh

This file was deleted.

0 comments on commit 5325dc0

Please sign in to comment.