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

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
darrylmendillo committed Dec 16, 2020
0 parents commit 3e8a4cb
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 0 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
21 changes: 21 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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 }}
6 changes: 6 additions & 0 deletions docker-compose.build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: "3.8"

services:

deploy:
build: .
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3e8a4cb

Please sign in to comment.