feat(gcp): adds virtual machine setup #63
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
name: build-images | |
on: | |
workflow_dispatch: | |
push: | |
paths: | |
- cmd/** | |
- infrastructure-templates/** | |
- terraform/** | |
- ".github/workflows/**" | |
- Dockerfile | |
- .ci/** | |
permissions: | |
contents: read | |
packages: write | |
jobs: | |
docker-builds: | |
strategy: | |
matrix: | |
name: | |
- infrastructure-as-code | |
- aws-spot-k3s-terminator | |
include: | |
- name: infrastructure-as-code | |
buildDir: . | |
imageRepo: ghcr.io/${{ github.repository }}/iac-job | |
- name: aws-spot-k3s-terminator | |
buildDir: cmd/aws-spot-k3s-terminator | |
imageRepo: ghcr.io/${{ github.repository }}/aws-spot-k3s-terminator | |
runs-on: ubuntu-latest | |
name: Deploy to Docker Image | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Log in to the Container registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create Image Tag from branch name | |
if: startsWith(github.ref, 'refs/heads/release') | |
run: | | |
set +e | |
IMAGE_TAG=$(echo ${GITHUB_REF#refs/heads/release-}) | |
echo "$IMAGE_TAG" | grep -i '\-nightly$' | |
if [ $? -ne 0 ]; then | |
IMAGE_TAG="$IMAGE_TAG-nightly" | |
fi | |
set -e | |
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV | |
echo "OVERRIDE_PUSHED_IMAGE=true" >> $GITHUB_ENV | |
- name: Create Image Tag from tag | |
if: startsWith(github.ref, 'refs/tags/') | |
run: | | |
IMAGE_TAG=$(echo ${GITHUB_REF#refs/tags/}) | |
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV | |
echo "OVERRIDE_PUSHED_IMAGE=false" >> $GITHUB_ENV | |
- name: Build & Push Image | |
if: startsWith(github.ref, 'refs/heads/release') || startsWith(github.ref, 'refs/tags/') | |
run: | | |
set +e | |
pushd ${{matrix.buildDir}} | |
image=${{matrix.imageRepo}}:$IMAGE_TAG | |
echo "building image: $image" | |
docker manifest inspect $image | |
exit_status=$? | |
if [ $exit_status -eq 0 ]; then | |
[ "$OVERRIDE_PUSHED_IMAGE" = "false" ] && echo "image ($image) already exists, and override image is disable, exiting" && exit 0 | |
echo "image exists, but override pushed image is set to true. proceeding with building image" | |
fi | |
set -e | |
docker buildx build -t $image . --push |