Skip to content

Commit

Permalink
Merge pull request #94 from WildMeOrg/git-build
Browse files Browse the repository at this point in the history
Git actions with automated build
  • Loading branch information
TanyaStere42 authored Jul 29, 2024
2 parents 5d655d7 + c83c275 commit 795a296
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/docker-image.yml
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



27 changes: 27 additions & 0 deletions build.sh
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
36 changes: 36 additions & 0 deletions publish.sh
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

0 comments on commit 795a296

Please sign in to comment.