Skip to content

Commit

Permalink
WIP: runner image in matrix build
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhail-sakhnov committed Oct 28, 2024
1 parent 29b2546 commit 3d82802
Show file tree
Hide file tree
Showing 2 changed files with 205 additions and 200 deletions.
349 changes: 177 additions & 172 deletions .github/workflows/build-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ env:
# See https://github.com/moby/buildkit/issues/2343 for more information.
GO_BASE_IMG: "localhost:5000/neondatabase/autoscaling-go-base:dev"
# Default architecture to build. In future it would be changed to multi-arch build or separate builds for each arch
TARGET_ARCH: "amd64"
TARGET_ARCH: "amd64" # move to matrix strategy

defaults:
run:
Expand All @@ -91,24 +91,28 @@ jobs:
echo "autoscaler-agent=${{ env.IMG_AUTOSCALER_AGENT }}:${{ inputs.tag }}" | tee -a $GITHUB_OUTPUT
echo "cluster-autoscaler=${{ env.IMG_CLUSTER_AUTOSCALER }}:${{ inputs.tag }}" | tee -a $GITHUB_OUTPUT
vm-kernel:
# nb: use format(..) to catch both inputs.skip = true AND inputs.skip = 'true'.
if: ${{ format('{0}', inputs.skip) != 'true' }}
uses: ./.github/workflows/vm-kernel.yaml
with:
tag: ${{ inputs.kernel-image || inputs.tag }}
return-image-for-tag: ${{ inputs.kernel-image }}
secrets: inherit
# vm-kernel:
# # nb: use format(..) to catch both inputs.skip = true AND inputs.skip = 'true'.
# if: ${{ format('{0}', inputs.skip) != 'true' }}
# uses: ./.github/workflows/vm-kernel.yaml
# with:
# tag: ${{ inputs.kernel-image || inputs.tag }}
# return-image-for-tag: ${{ inputs.kernel-image }}
# secrets: inherit

build:
# nb: use format(..) to catch both inputs.skip = true AND inputs.skip = 'true'.
if: ${{ format('{0}', inputs.skip) != 'true' }}
needs: [ tags, vm-kernel ]
runs-on: [ self-hosted, large ]
needs: [ tags ] # vm-kernel ]
permissions:
contents: read # This is required for actions/checkout
id-token: write # This is required for aws-actions/configure-aws-credentials

strategy:
matrix:
arch: [ 'amd64'] # 'arm64' ]
runs-on: ${{ fromJson(format('["self-hosted", "{0}"]', matrix.arch == 'arm64' && 'large-arm64' || 'large')) }}

services:
registry:
image: registry:2
Expand Down Expand Up @@ -165,170 +169,171 @@ jobs:
username: ${{ secrets.NEON_CI_DOCKERCACHE_USERNAME }}
password: ${{ secrets.NEON_CI_DOCKERCACHE_PASSWORD }}

- name: Configure dev AWS credentials
if: ${{ format('{0}', inputs.upload-to-ecr) == 'true' }}
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: eu-central-1
mask-aws-account-id: true
role-to-assume: ${{ secrets.DEV_GHA_OIDC_ECR_ROLE }}

- name: Login to dev ECR
if: ${{ format('{0}', inputs.upload-to-ecr) == 'true' }}
uses: docker/login-action@v3
with:
registry: ${{ env.ECR_DEV }}

- name: Configure prod AWS credentials
if: ${{ format('{0}', inputs.upload-to-ecr) == 'true' }}
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: eu-central-1
mask-aws-account-id: true
role-to-assume: ${{ secrets.PROD_GHA_OIDC_ECR_ROLE }}

- name: Login to prod ECR
if: ${{ format('{0}', inputs.upload-to-ecr) == 'true' }}
uses: docker/login-action@v3
with:
registry: ${{ env.ECR_PROD }}
# - name: Configure dev AWS credentials
# if: ${{ format('{0}', inputs.upload-to-ecr) == 'true' }}
# uses: aws-actions/configure-aws-credentials@v4
# with:
# aws-region: eu-central-1
# mask-aws-account-id: true
# role-to-assume: ${{ secrets.DEV_GHA_OIDC_ECR_ROLE }}

# - name: Login to dev ECR
# if: ${{ format('{0}', inputs.upload-to-ecr) == 'true' }}
# uses: docker/login-action@v3
# with:
# registry: ${{ env.ECR_DEV }}

# - name: Configure prod AWS credentials
# if: ${{ format('{0}', inputs.upload-to-ecr) == 'true' }}
# uses: aws-actions/configure-aws-credentials@v4
# with:
# aws-region: eu-central-1
# mask-aws-account-id: true
# role-to-assume: ${{ secrets.PROD_GHA_OIDC_ECR_ROLE }}

# - name: Login to prod ECR
# if: ${{ format('{0}', inputs.upload-to-ecr) == 'true' }}
# uses: docker/login-action@v3
# with:
# registry: ${{ env.ECR_PROD }}

- name: Check dependencies
run: |
docker version
docker buildx version
- name: Load VM kernel
env:
IMAGE: ${{ needs.vm-kernel.outputs.image }}
run: |
docker pull --quiet $IMAGE
ID=$(docker create $IMAGE true)
docker cp ${ID}:/vmlinuz neonvm-kernel/vmlinuz
docker rm -f ${ID}
- name: Build go dependencies image
uses: docker/build-push-action@v6
id: build-go-dependencies-image
with:
context: .
platforms: linux/amd64
push: true
file: Dockerfile.go-base
cache-from: type=registry,ref=cache.neon.build/autoscaling-go-base:cache
cache-to: ${{ github.ref_name == 'main' && 'type=registry,ref=cache.neon.build/autoscaling-go-base:cache,mode=max' || '' }}
tags: ${{ env.GO_BASE_IMG }}

- name: Build and push neonvm-runner image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
push: true
file: neonvm-runner/Dockerfile
cache-from: type=registry,ref=cache.neon.build/neonvm-runner:cache
cache-to: ${{ github.ref_name == 'main' && 'type=registry,ref=cache.neon.build/neonvm-runner:cache,mode=max' || '' }}
tags: ${{ needs.tags.outputs.runner }}
build-args: |
GO_BASE_IMG=${{ env.GO_BASE_IMG }}
- name: Generate neonvm-controller build tags
id: controller-build-tags
env:
PRESERVE_RUNNER_PODS: ${{ inputs.controller-preserve-runner-pods }}
run: |
if [ "$PRESERVE_RUNNER_PODS" = 'true' ]; then
echo "buildtags=nodelete" | tee -a $GITHUB_OUTPUT
else
echo "buildtags=" | tee -a $GITHUB_OUTPUT
fi
- name: Build and push neonvm-controller image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
push: true
file: neonvm-controller/Dockerfile
cache-from: type=registry,ref=cache.neon.build/neonvm-controller:cache
cache-to: ${{ github.ref_name == 'main' && 'type=registry,ref=cache.neon.build/neonvm-controller:cache,mode=max' || '' }}
tags: ${{ needs.tags.outputs.controller }}
build-args: |
GO_BASE_IMG=${{ env.GO_BASE_IMG }}
VM_RUNNER_IMAGE=${{ needs.tags.outputs.runner }}
BUILDTAGS=${{ steps.controller-build-tags.outputs.buildtags }}
- name: Build and push neonvm-vxlan-controller image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
push: true
file: neonvm-vxlan-controller/Dockerfile
cache-from: type=registry,ref=cache.neon.build/neonvm-vxlan-controller:cache
cache-to: ${{ github.ref_name == 'main' && 'type=registry,ref=cache.neon.build/neonvm-vxlan-controller:cache,mode=max' || '' }}
tags: ${{ needs.tags.outputs.vxlan-controller }}
build-args: |
GO_BASE_IMG=${{ env.GO_BASE_IMG }}
TARGET_ARCH=${{ env.TARGET_ARCH }}
- name: Build and push autoscale-scheduler image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
push: true
file: autoscale-scheduler/Dockerfile
cache-from: type=registry,ref=cache.neon.build/autoscale-scheduler:cache
cache-to: ${{ github.ref_name == 'main' && 'type=registry,ref=cache.neon.build/autoscale-scheduler:cache,mode=max' || '' }}
tags: ${{ needs.tags.outputs.scheduler }}
build-args: |
GO_BASE_IMG=${{ env.GO_BASE_IMG }}
GIT_INFO=${{ steps.get-git-info.outputs.info }}:${{ inputs.tag }}
- name: Build and push autoscaler-agent image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
push: true
file: autoscaler-agent/Dockerfile
cache-from: type=registry,ref=cache.neon.build/autoscaler-agent:cache
cache-to: ${{ github.ref_name == 'main' && 'type=registry,ref=cache.neon.build/autoscaler-agent:cache,mode=max' || '' }}
tags: ${{ needs.tags.outputs.autoscaler-agent }}
build-args: |
GO_BASE_IMG=${{ env.GO_BASE_IMG }}
GIT_INFO=${{ steps.get-git-info.outputs.info }}
- name: Build and push cluster-autoscaler image
uses: docker/build-push-action@v6
if: ${{ format('{0}', inputs.build-cluster-autoscaler) == 'true' }}
with:
context: cluster-autoscaler
platforms: linux/amd64
push: true
tags: ${{ needs.tags.outputs.cluster-autoscaler }}
cache-from: type=registry,ref=cache.neon.build/cluster-autoscaler-neonvm:cache
cache-to: ${{ github.ref_name == 'main' && 'type=registry,ref=cache.neon.build/cluster-autoscaler-neonvm:cache,mode=max' || '' }}
build-args: |
CA_GIT_TAG=${{ steps.get-ca-tag.outputs.tag }}
- name: Copy all images to ECR
if: ${{ format('{0}', inputs.upload-to-ecr) == 'true' }}
run: |
for image in \
neonvm-controller \
neonvm-vxlan-controller \
neonvm-runner \
vm-kernel \
autoscale-scheduler \
autoscaler-agent \
cluster-autoscaler-neonvm \
; do
echo Copy ${image}:${{ inputs.tag }} to dev ECR
docker buildx imagetools create -t ${{ env.ECR_DEV }}/${image}:${{ inputs.tag }} \
neondatabase/${image}:${{ inputs.tag }}
echo Copy ${image}:${{ inputs.tag }} to prod ECR
docker buildx imagetools create -t ${{ env.ECR_PROD }}/${image}:${{ inputs.tag }} \
neondatabase/${image}:${{ inputs.tag }}
done
# - name: Load VM kernel
# env:
# IMAGE: ${{ needs.vm-kernel.outputs.image }}
# run: |
# docker pull --quiet $IMAGE
# ID=$(docker create $IMAGE true)
# docker cp ${ID}:/vmlinuz neonvm-kernel/vmlinuz
# docker rm -f ${ID}
- run: uname -a
- run: echo "${{ matrix.arch }}"
# - name: Build go dependencies image
# uses: docker/build-push-action@v6
# id: build-go-dependencies-image
# with:
# context: .

# push: true
# file: Dockerfile.go-base
# cache-from: type=registry,ref=cache.neon.build/autoscaling-go-base:cache
# cache-to: ${{ github.ref_name == 'main' && 'type=registry,ref=cache.neon.build/autoscaling-go-base:cache,mode=max' || '' }}
# tags: ${{ env.GO_BASE_IMG }}

# - name: Build and push neonvm-runner image
# uses: docker/build-push-action@v6
# with:
# context: .

# push: true
# file: neonvm-runner/Dockerfile
# cache-from: type=registry,ref=cache.neon.build/neonvm-runner:cache
# cache-to: ${{ github.ref_name == 'main' && 'type=registry,ref=cache.neon.build/neonvm-runner:cache,mode=max' || '' }}
# tags: ${{ needs.tags.outputs.runner }}
# build-args: |
# GO_BASE_IMG=${{ env.GO_BASE_IMG }}

# - name: Generate neonvm-controller build tags
# id: controller-build-tags
# env:
# PRESERVE_RUNNER_PODS: ${{ inputs.controller-preserve-runner-pods }}
# run: |
# if [ "$PRESERVE_RUNNER_PODS" = 'true' ]; then
# echo "buildtags=nodelete" | tee -a $GITHUB_OUTPUT
# else
# echo "buildtags=" | tee -a $GITHUB_OUTPUT
# fi

# - name: Build and push neonvm-controller image
# uses: docker/build-push-action@v6
# with:
# context: .

# push: true
# file: neonvm-controller/Dockerfile
# cache-from: type=registry,ref=cache.neon.build/neonvm-controller:cache
# cache-to: ${{ github.ref_name == 'main' && 'type=registry,ref=cache.neon.build/neonvm-controller:cache,mode=max' || '' }}
# tags: ${{ needs.tags.outputs.controller }}
# build-args: |
# GO_BASE_IMG=${{ env.GO_BASE_IMG }}
# VM_RUNNER_IMAGE=${{ needs.tags.outputs.runner }}
# BUILDTAGS=${{ steps.controller-build-tags.outputs.buildtags }}

# - name: Build and push neonvm-vxlan-controller image
# uses: docker/build-push-action@v6
# with:
# context: .

# push: true
# file: neonvm-vxlan-controller/Dockerfile
# cache-from: type=registry,ref=cache.neon.build/neonvm-vxlan-controller:cache
# cache-to: ${{ github.ref_name == 'main' && 'type=registry,ref=cache.neon.build/neonvm-vxlan-controller:cache,mode=max' || '' }}
# tags: ${{ needs.tags.outputs.vxlan-controller }}
# build-args: |
# GO_BASE_IMG=${{ env.GO_BASE_IMG }}
# TARGET_ARCH=${{ env.TARGET_ARCH }}

# - name: Build and push autoscale-scheduler image
# uses: docker/build-push-action@v6
# with:
# context: .

# push: true
# file: autoscale-scheduler/Dockerfile
# cache-from: type=registry,ref=cache.neon.build/autoscale-scheduler:cache
# cache-to: ${{ github.ref_name == 'main' && 'type=registry,ref=cache.neon.build/autoscale-scheduler:cache,mode=max' || '' }}
# tags: ${{ needs.tags.outputs.scheduler }}
# build-args: |
# GO_BASE_IMG=${{ env.GO_BASE_IMG }}
# GIT_INFO=${{ steps.get-git-info.outputs.info }}:${{ inputs.tag }}

# - name: Build and push autoscaler-agent image
# uses: docker/build-push-action@v6
# with:
# context: .

# push: true
# file: autoscaler-agent/Dockerfile
# cache-from: type=registry,ref=cache.neon.build/autoscaler-agent:cache
# cache-to: ${{ github.ref_name == 'main' && 'type=registry,ref=cache.neon.build/autoscaler-agent:cache,mode=max' || '' }}
# tags: ${{ needs.tags.outputs.autoscaler-agent }}
# build-args: |
# GO_BASE_IMG=${{ env.GO_BASE_IMG }}
# GIT_INFO=${{ steps.get-git-info.outputs.info }}

# - name: Build and push cluster-autoscaler image
# uses: docker/build-push-action@v6
# if: ${{ format('{0}', inputs.build-cluster-autoscaler) == 'true' }}
# with:
# context: cluster-autoscaler

# push: true
# tags: ${{ needs.tags.outputs.cluster-autoscaler }}
# cache-from: type=registry,ref=cache.neon.build/cluster-autoscaler-neonvm:cache
# cache-to: ${{ github.ref_name == 'main' && 'type=registry,ref=cache.neon.build/cluster-autoscaler-neonvm:cache,mode=max' || '' }}
# build-args: |
# CA_GIT_TAG=${{ steps.get-ca-tag.outputs.tag }}

# - name: Copy all images to ECR
# if: ${{ format('{0}', inputs.upload-to-ecr) == 'true' }}
# run: |
# for image in \
# neonvm-controller \
# neonvm-vxlan-controller \
# neonvm-runner \
# # vm-kernel \
# autoscale-scheduler \
# autoscaler-agent \
# cluster-autoscaler-neonvm \
# ; do
# echo Copy ${image}:${{ inputs.tag }} to dev ECR
# docker buildx imagetools create -t ${{ env.ECR_DEV }}/${image}:${{ inputs.tag }} \
# neondatabase/${image}:${{ inputs.tag }}
# echo Copy ${image}:${{ inputs.tag }} to prod ECR
# docker buildx imagetools create -t ${{ env.ECR_PROD }}/${image}:${{ inputs.tag }} \
# neondatabase/${image}:${{ inputs.tag }}
# done
Loading

0 comments on commit 3d82802

Please sign in to comment.