Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/docker-img.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Build and deploy Docker images

on: push

jobs:
build:
name: Build image '${{ matrix.version }}'

if: ${{ github.repository_owner == 'varigit' }}

strategy:
matrix:
version:
- 14.04
- 16.04
- 18.04
- 20.04
- 22.04

runs-on: ubuntu-20.04

steps:
- name: Checkout source code
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744

- name: Get commit SHA
run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-8`" >> $GITHUB_ENV

- name: Login to GitHub Packages
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@b32b51a8eda65d6793cd0494a773d4f6bcef32dc
with:
context: .
push: true
tags:
ghcr.io/${{ github.repository }}/yocto-env:${{ matrix.version }}-${{ env.SHORT_SHA }},
ghcr.io/${{ github.repository }}/yocto-env:${{ matrix.version }}-latest
file: Dockerfile_${{ matrix.version }}

22 changes: 14 additions & 8 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
readonly FILE_SCRIPT="$(basename "$0")"
readonly DIR_SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
readonly GIT_COMMIT="$(git --git-dir=${DIR_SCRIPT}/.git log -1 --format=%h)"
readonly PKG_REGISTRY="ghcr.io/varigit/var-host-docker-containers/yocto-env"

cd ${DIR_SCRIPT}

Expand All @@ -25,7 +26,7 @@ build_image() {
echo "${DIR_SCRIPT}/${DOCKERFILE} not found"
exit -1
fi
docker build ${BUILD_CACHE} -t "variscite:${DOCKER_IMAGE}" ${DIR_SCRIPT} -f ${DOCKERFILE}
docker build ${BUILD_CACHE} -t "${PKG_REGISTRY}:${DOCKER_IMAGE}" ${DIR_SCRIPT} -f ${DOCKERFILE}
}

array_contains () {
Expand Down Expand Up @@ -179,7 +180,7 @@ set_quirks() {

parse_args "$@"

readonly DOCKER_IMAGE="yocto-${UBUNTU_VERSION}-${GIT_COMMIT}"
readonly DOCKER_IMAGE="${UBUNTU_VERSION}-latest"
readonly HOSTNAME=$( echo "$DOCKER_IMAGE" | sed 's/\./-/g')

# Verify qemu-user-static is installed
Expand All @@ -188,11 +189,16 @@ if [ ! -f /usr/bin/qemu-aarch64-static ]; then
exit -1
fi

# Build container if the image does not exist, the cache needs to be rebuilt, or the build flag is set
if ! docker images | grep -q "${DOCKER_IMAGE}" \
|| [ -n "$BUILD_CACHE" ] \
|| [ $BUILD_IMAGE_FLAG -eq 1 ]; then
build_image "Dockerfile_${UBUNTU_VERSION}"
# Pull the image or Build it if the image does not exist, the cache needs to be rebuilt, or the build flag is set
if ! docker images | grep -q "${DOCKER_IMAGE}"; then
if [ -z "$BUILD_CACHE" ] && [ $BUILD_IMAGE_FLAG -ne 1 ]; then
docker manifest inspect "${PKG_REGISTRY}:${DOCKER_IMAGE}" > /dev/null 2>&1
if [ $? -eq 0 ]; then
docker pull "${PKG_REGISTRY}:${DOCKER_IMAGE}"
fi
else
build_image "Dockerfile_${UBUNTU_VERSION}"
fi
fi

uid=$(id -u ${USER})
Expand Down Expand Up @@ -224,4 +230,4 @@ docker run ${EXTRA_ARGS} --rm -e HOST_USER_ID=$uid -e HOST_USER_GID=$gid \
${DOCKER_HOST_NETWORK} \
--cpus=${CPUS} \
${QUIRKS} \
variscite:${DOCKER_IMAGE} "$COMMAND"
${PKG_REGISTRY}:${DOCKER_IMAGE} "$COMMAND"