From 3e8a4cbeb12ff6ff1bdcb479ce4578528e6ff3cf Mon Sep 17 00:00:00 2001 From: Darryl Mendillo <1238655+darrylmendillo@users.noreply.github.com> Date: Wed, 16 Dec 2020 15:01:50 -0500 Subject: [PATCH] initial commit --- .github/workflows/publish.yml | 72 +++++++++++++++++++++++++++++++++++ Dockerfile | 8 ++++ LICENSE | 21 ++++++++++ README.md | 16 ++++++++ action.yml | 21 ++++++++++ docker-compose.build.yml | 6 +++ docker-compose.yml | 12 ++++++ entrypoint.sh | 24 ++++++++++++ 8 files changed, 180 insertions(+) create mode 100644 .github/workflows/publish.yml create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 action.yml create mode 100644 docker-compose.build.yml create mode 100644 docker-compose.yml create mode 100755 entrypoint.sh diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..38a5607 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,72 @@ +name: publish + +on: + release: + types: + - published + +jobs: + + publish: + runs-on: ubuntu-latest + + 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 + with: + name: env + path: .env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cfa24b1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +ARG VERSION="0.2.9" + +FROM jrasell/levant:${VERSION} as deploy +LABEL name="deploy" + +ADD entrypoint.sh /entrypoint.sh + +ENTRYPOINT [ "/entrypoint.sh" ] \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ff4e1c1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Penn Signals + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..57dfd19 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# Levant Deploy + +A GitHub Action that finds all nomad jobs and deploys them +## Features + +Searches all subdirectories accoring to `config`. All matched files will be rendered and deployed to Nomad. + +## Example Usage +``` + - name: deploy + uses: pennsignals/deploy_actio@v1.0.0 + with: + versiob: '0.2.6-rc.1' # required + config: './deploy_config.yml' # required + +``` \ No newline at end of file diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..22de6fc --- /dev/null +++ b/action.yml @@ -0,0 +1,21 @@ +# action.yml +name: "Levant Deploy" +author: "Darryl Mendillo" +description: "Template and deploy all nomad jobs matching regex in config" +branding: + icon: "database" + color: "red" +inputs: + version: + description: "Release version (tag)" + required: true + config: + description: "deploy_config.yml file with all deployment settings" + required: true + +runs: + using: "docker" + image: "Dockerfile" + args: + - ${{ inputs.version }} + - ${{ inputs.config }} diff --git a/docker-compose.build.yml b/docker-compose.build.yml new file mode 100644 index 0000000..844d474 --- /dev/null +++ b/docker-compose.build.yml @@ -0,0 +1,6 @@ +version: "3.8" + +services: + + deploy: + build: . diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d993f52 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: "3.8" + +services: + + deploy: + build: . + environment: + - INPUT_CONFIG=deploy_config.yml + - INPUT_VERSIOB=1.0.0 + volumes: + - ./:/source + working_dir: /source \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..a8d83c4 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +# echo all the variabls +echo "INPUT_ADDR: $INPUT_VERSION" +echo "INPUT_CONFIG: $INPUT_CONFIG" + +# use levant to deploy service nomad jobs as templates +for dir in */ ; do + if [ -d "${dir}nomad" ]; then + + echo "Deploying jobs from: ${dir}nomad." + for file in ${dir}nomad/*; do + matched=$([[ $file =~ ^.*.nomad.hcl$ ]] && echo "true" || echo "false") + + # only deploy *.nomad.hcl (jobs) + if [ $matched = "true" ]; then + echo "levant deploy -var TAG=${INPUT_VERSION} -ignore-no-changes -var DEPLOY=staging -var-file=${INPUT_CONFIG} ${file}" + levant render -var TAG=${INPUT_VERSION} -var DEPLOY=staging -var-file=${INPUT_CONFIG} -out=nomad/$(basename $file) ${file} + levant deploy -var TAG=${INPUT_VERSION} -ignore-no-changes -var DEPLOY=staging -var-file=${INPUT_CONFIG} ${file} + fi + + done + fi +done \ No newline at end of file