Skip to content

Commit

Permalink
Add new build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisnharvey committed May 7, 2020
1 parent 9ce308c commit a2daaf2
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 5 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ jobs:
steps:
- uses: actions/checkout@v1

- name: Build the Docker images
run: docker-compose build

- uses: azure/docker-login@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
email: ${{ secrets.DOCKER_EMAIL }}

- name: Push images to registry
run: docker-compose push
- name: Build and push images to registry
run: scripts/build.sh
25 changes: 25 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

. "${BASH_SOURCE%/*}/utils.sh"

translateDockerTag

for container_path in ${BASH_SOURCE%/*}/../containers/default/* ; do

container_name="chrisnharvey/magiclamp-$(basename $container_path)"

BUILD_TAGS=""

for TAG in ${TAGS}
do
BUILD_TAGS="${BUILD_TAGS}-t ${container_name}:${TAG} "
done

docker build ${BUILD_TAGS} ${container_path}

for TAG in ${TAGS}
do
docker push "${container_name}:${TAG}"
done

done
63 changes: 63 additions & 0 deletions scripts/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

# The following was taken from great work by Lars (elgohr)
# Copyright (c) 2019 Lars
# https://github.com/elgohr/Publish-Docker-Github-Action

function translateDockerTag() {

local BRANCH=$(echo ${GITHUB_REF} | sed -e "s/refs\/heads\///g" | sed -e "s/\//-/g")

if isOnMaster; then

TAGS="latest"

elif isGitTag && isSemver "${GITHUB_REF}"; then

TAGS=$(echo ${GITHUB_REF} | sed -e "s/refs\/tags\///g" | sed -E "s/v?([0-9]+)\.([0-9+])\.([0-9]+)(-[a-zA-Z]+(\.[0-9]+)?)?/\1.\2.\3\4 \1.\2\4 \1\4/g")

elif isGitTag; then

TAGS="latest"

elif isPullRequest; then

TAGS="${GITHUB_SHA}"

else

TAGS="${BRANCH}-dev"

fi;

}


function isSemver() {

echo "${1}" | grep -Eq '^refs/tags/v?([0-9]+)\.([0-9+])\.([0-9]+)(-[a-zA-Z]+(\.[0-9]+)?)?$'

}


function isOnMaster() {

[ "${BRANCH}" = "master" ]

}



function isGitTag() {

[ $(echo "${GITHUB_REF}" | sed -e "s/refs\/tags\///g") != "${GITHUB_REF}" ]

}



function isPullRequest() {

[ $(echo "${GITHUB_REF}" | sed -e "s/refs\/pull\///g") != "${GITHUB_REF}" ]

}

0 comments on commit a2daaf2

Please sign in to comment.