-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from WildMeOrg/git-build
Git actions with automated build
- Loading branch information
Showing
3 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Build and upload Docker for Scout | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
devops: | ||
name: Docker image build | ||
runs-on: ubuntu-latest | ||
permissions: | ||
packages: write | ||
strategy: | ||
matrix: | ||
images: | ||
- main | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
if: github.event_name == 'push' | ||
with: | ||
ref: git-build | ||
|
||
- name: Free Disk space | ||
run: | | ||
sudo swapoff -a | ||
sudo rm -f /swapfile | ||
sudo rm -rf /opt/hostedtoolcache | ||
sudo apt clean | ||
docker rmi $(docker image ls -aq) | ||
df -h | ||
# Build images | ||
- name: Build images | ||
run: | | ||
# Build Image | ||
bash ./build.sh ${{ matrix.images }} | ||
# Log into image registries | ||
- name: Login to DockerHub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: wildmeorg | ||
password: ${{ secrets.WBIA_WILDMEBOT_DOCKER_HUB_TOKEN }} | ||
|
||
- name: Push to Docker Hub (Latest) | ||
if: ${{ github.event_name == 'push' }} | ||
run: | | ||
VERSION=$(echo ${GITHUB_REF} | sed 's#.*/v##') | ||
bash ./publish.sh -t latest ${PUBLISH_IMAGES} | ||
env: | ||
PUBLISH_IMAGES: ${{ matrix.images }} scout | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env bash | ||
|
||
# See https://stackoverflow.com/a/246128/176882 | ||
export ROOT_LOC="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
|
||
export DOCKER_BUILDKIT=1 | ||
|
||
export DOCKER_CLI_EXPERIMENTAL=enabled | ||
|
||
# Change to the script's root directory location | ||
cd ${ROOT_LOC} | ||
|
||
# Build the images in dependence order | ||
while [ $# -ge 1 ]; do | ||
if [ "$1" == "scout" ]; then | ||
echo "Current working directory: $PWD" | ||
docker build \ | ||
--compress \ | ||
-t wildme/scout:latest \ | ||
--no-cache \ | ||
. | ||
else | ||
echo "Image $1 not found" | ||
exit 1 | ||
fi | ||
shift | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
usage () { | ||
echo "Usage: $0 [-t <tag>] [-r <registry-url>] [<image> ...]"; | ||
} | ||
|
||
# Parse commandline options | ||
while getopts ":t:r:" option; do | ||
case ${option} in | ||
t ) TAG=${OPTARG};; | ||
r ) REGISTRY=${OPTARG};; | ||
\? ) usage; exit 1;; | ||
esac | ||
done | ||
shift $((OPTIND - 1)) | ||
|
||
# Assign variables | ||
TAG=${TAG:-latest} | ||
REGISTRY=${REGISTRY:-} | ||
IMAGES=${@:-scout} | ||
# Set the image prefix | ||
if [ -n "$REGISTRY" ]; then | ||
IMG_PREFIX="${REGISTRY}/" | ||
else | ||
IMG_PREFIX="wildme/" | ||
fi | ||
|
||
# Tag built images from `build.sh`, which tags as `latest` | ||
for IMG in $IMAGES; do | ||
echo "Tagging scout/${IMG}:latest --> ${IMG_PREFIX}${IMG}:${TAG}" | ||
docker tag wildme/${IMG}:latest ${IMG_PREFIX}${IMG}:${TAG} | ||
echo "Pushing ${IMG_PREFIX}${IMG}:${TAG}" | ||
docker push ${IMG_PREFIX}${IMG}:${TAG} | ||
done |