Skip to content

Commit

Permalink
Merge branch 'main' into VEC-440-Unify-github-actions-for-clean-build…
Browse files Browse the repository at this point in the history
…-and-release
  • Loading branch information
arrowplum committed Jan 4, 2025
2 parents 3869103 + 43b7eac commit 317d6e8
Show file tree
Hide file tree
Showing 20 changed files with 290 additions and 97 deletions.
148 changes: 106 additions & 42 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ on:
version:
description: 'Version to build and deploy'
required: false

is_release:
description: 'Is this a release build?'
required: false
default: false
type: boolean

env:
REPO: 'artifact.aerospike.io/ecosystem-container-dev-local'
JFROG_CLI_BUILD_NAME: 'asvec'

JFROG_CLI_LOG_LEVEL: DEBUG
JFROG_CLI_BUILD_PROJECT: 'ecosystem'
jobs:
build-and-push:
runs-on: ubuntu-latest
Expand All @@ -43,9 +49,6 @@ jobs:
- name: Login to Artifact Aerospike Docker Registry
run: |
jf docker login artifact.aerospike.io --username ${{ secrets.JFROG_USERNAME }} --password ${{ secrets.JFROG_ACCESS_TOKEN }}
# needed these to get the docker cache working
docker pull artifact.aerospike.io/ecosystem-container-dev-local/asvec:latest || true
docker push artifact.aerospike.io/ecosystem-container-dev-local/asvec:latest || true
env:
JFROG_CLI_OFFER_CONFIG: 'false'

Expand All @@ -63,82 +66,143 @@ jobs:

- name: Set Version
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ] && [ -n "${{ github.event.inputs.version }}" ]; then
VERSION_ARG="${{ github.event.inputs.version }}"
elif [ "${{ github.event_name }}" == "push" ] && [[ "${{ github.ref }}" == refs/tags/* ]]; then
VERSION_ARG="${GITHUB_REF#refs/tags/}"
# Initialize variables
VERSION_ARG=""
VERSION=""
IS_RELEASE="${{ github.event.inputs.is_release }}"
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
# On tag push: Use the tag name as the version
VERSION="${GITHUB_REF#refs/tags/}"
elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
# On manual trigger
if [ -n "${{ github.event.inputs.version }}" ]; then
VERSION_ARG="${{ github.event.inputs.version }}"
else
# If no version input provided, default to RELEASE file
VERSION_ARG=$(cat RELEASE)
fi
if [ "${IS_RELEASE}" == 'true' ]; then
# If release checkbox is checked, use version directly
VERSION="${VERSION_ARG}"
else
# If not release, append build ID
VERSION="${VERSION_ARG}-${GITHUB_RUN_NUMBER}"
fi
else
# In all other cases: Use RELEASE file content appended with build ID
VERSION_ARG=$(cat RELEASE)
VERSION="${VERSION_ARG}-${GITHUB_RUN_NUMBER}"
fi
BUILD_ID=${GITHUB_RUN_NUMBER}
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
VERSION="${VERSION_ARG}"
else
VERSION="${VERSION_ARG}-${BUILD_ID}"
fi
echo "VERSION=${VERSION}" >> $GITHUB_ENV
- name: Build Docker Image (No Push)
if: github.event_name == 'pull_request'
run: |
jf docker buildx bake \
--set asvec.args.VERSION_ARG=${{ env.VERSION }} \
--set asvec.args.REPO=${{ env.REPO }} \
--set asvec.tags.0=asvec:test-${{ github.run_id }} \
--file docker/asvec.docker/bake.hcl \
env:
DOCKER_BUILDKIT: '1'

- name: Build and Push Docker Image
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
run: |
jf docker buildx bake \
--set asvec.args.VERSION_ARG=${{ env.VERSION }} \
--set asvec.args.REPO=${{ env.REPO }} \
--set asvec.tags.0=${{ env.REPO }}/asvec:${{ env.VERSION }} \
--set asvec.tags=${{ env.REPO }}/asvec:${{ env.VERSION }} \
--file docker/asvec.docker/bake.hcl \
--push \
--metadata-file=build-metadata
env:
DOCKER_BUILDKIT: '1'

- name: Build and Push Docker Image with 'latest' Tag (Release)
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
run: |
jf docker buildx bake \
--set asvec.args.VERSION_ARG=${{ env.VERSION }} \
--set asvec.args.REPO=${{ env.REPO }} \
--set asvec.tags.0=${{ env.REPO }}/asvec:${{ env.VERSION }} \
--set asvec.tags.1=${{ env.REPO }}/asvec:latest \
--file docker/asvec.docker/bake.hcl \
--push \
--metadata-file=build-metadata
env:
DOCKER_BUILDKIT: '1'

- name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq

- name: Extract Image Name and Digest
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')))
run: |
jq -r '.[] | {digest: .["containerimage.digest"], names: .["image.name"] | split(",")} | "\(.names[0])@\(.digest)"' build-metadata > meta-info
jq -r '.[] | {digest: .["containerimage.digest"], names: .["image.name"] | split(",")} | "(.digest)"' build-metadata > sha
echo ${{ env.REPO }}/asvec:${{ env.VERSION }}@$(cat sha) > meta-info
echo ${{ env.REPO }}/asvec:${{ env.VERSION }}@$(cat sha) > meta-info-latest
- name: Create Docker Build Info
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))

if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')))
run: |
jf rt build-docker-create \
--build-name "${{ env.JFROG_CLI_BUILD_NAME }}" \
--build-name "${{ env.JFROG_CLI_BUILD_NAME }}-container" \
--build-number "${{ env.VERSION }}" \
--image-file ./meta-info \
--project ecosystem \
ecosystem-container-dev-local
- name: Publish Build Info
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')))
run: |
export JFROG_CLI_LOG_LEVEL=DEBUG
jf rt build-collect-env --project ecosystem "${{ env.JFROG_CLI_BUILD_NAME }}-container" "${{ env.VERSION }}"
jf rt build-add-git --project ecosystem "${{ env.JFROG_CLI_BUILD_NAME }}-container" "${{ env.VERSION }}"
jf rt build-publish \
--detailed-summary \
--project ecosystem \
"${{ env.JFROG_CLI_BUILD_NAME }}" "${{ env.VERSION }}"
"${{ env.JFROG_CLI_BUILD_NAME }}-container" "${{ env.VERSION }}"
# All of the following steps are commented out because they are just to handle "latest" tag and it is typically not desired in a release bundle
# - name: Tag a release with latest (Release)
# if: github.event_name == 'workflow_dispatch' && github.event.inputs.is_release == 'true' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/'))
# run: |
# jf docker buildx imagetools create --tag ${{ env.REPO }}/asvec:latest ${{ env.REPO }}/asvec:${{ env.VERSION }}
# env:
# DOCKER_BUILDKIT: '1'

# - name: Create Docker Build Info for latest
# if: github.event_name == 'workflow_dispatch' && github.event.inputs.is_release == 'true' || (github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/')))
# run: |

# jf rt build-docker-create \
# --build-name "${{ env.JFROG_CLI_BUILD_NAME }}-container-latest" \
# --build-number "${{ env.VERSION }}" \
# --image-file ./meta-info \
# --project ecosystem \
# ecosystem-container-dev-local

# - name: Publish Build Info for latest
# if: github.event_name == 'workflow_dispatch' && github.event.inputs.is_release == 'true' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/'))
# run: |
# jfrog rt build-collect-env "${{ env.JFROG_CLI_BUILD_NAME }}-container-latest" "${{ env.VERSION }}"
# jfrog rt build-add-git "${{ env.JFROG_CLI_BUILD_NAME }}-container-latest" "${{ env.VERSION }}"
# jfrog rt build-add-dependencies "${{ env.JFROG_CLI_BUILD_NAME }}-container-latest" "${{ env.VERSION }}".
# jf rt build-publish \
# --detailed-summary \
# --project ecosystem \
# "${{ env.JFROG_CLI_BUILD_NAME }}-container-latest" "${{ env.VERSION }}"

- name: Create Release Bundle
if: github.event_name == 'workflow_dispatch' && github.event.inputs.is_release == 'true'|| (github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/')))
run: |
echo '{
"name": "${{ env.JFROG_CLI_BUILD_NAME }}",
"version": "${{ env.VERSION }}",
"description": "Release bundle for ${{github.repository}} version ${{ env.VERSION }}",
"files": [
{
"project": "ecosystem",
"build": "${{ env.JFROG_CLI_BUILD_NAME }}-container"
}
]
}' > release-bundle-spec.json
cat release-bundle-spec.json
jf release-bundle-create \
"${{ env.JFROG_CLI_BUILD_NAME }}" "${{ env.VERSION }}"\
--project ecosystem \
--spec release-bundle-spec.json \
--signing-key aerospike --sync
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ VERSION.md
build-metadata
bin/asvec-linux-amd64
docker/asvec.docker/meta-info
meta-info
2 changes: 1 addition & 1 deletion RELEASE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0-pre
3.1.0
19 changes: 18 additions & 1 deletion cmd/writers/nodeList.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,17 @@ func NewNodeTableWriter(writer io.Writer, isLB bool, logger *slog.Logger) *NodeT
t := NodeTableWriter{NewDefaultWriter(writer), isLB, logger}

t.table.SetTitle("Nodes")
t.table.AppendHeader(table.Row{"Node", "Endpoint", "Cluster ID", "Version", "Visible Nodes"}, rowConfigAutoMerge)
t.table.AppendHeader(
table.Row{
"Node",
"Roles",
"Endpoint",
"Cluster ID",
"Version",
"Visible Nodes",
},
rowConfigAutoMerge,
)
t.table.SetAutoIndex(true)
t.table.SortBy([]table.SortBy{
{Name: "Node", Mode: table.Asc},
Expand Down Expand Up @@ -59,6 +69,13 @@ func (itw *NodeTableWriter) AppendNodeRow(node *NodeInfo) {
row = append(row, id)
}

// If the node is a load balancer, it does not have roles.
if !itw.isLB {
row = append(row, formatRoles(node.About.GetRoles()))
} else {
row = append(row, "N/A")
}

row = append(row, formatEndpoint(node.ConnectedEndpoint))

if node.State != nil {
Expand Down
14 changes: 14 additions & 0 deletions cmd/writers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ func formatEndpoints(nodeID uint64, nodeEndpoints map[uint64]*protos.ServerEndpo
return strings.Join(nodeToEndpointsStr, "\n")
}

func formatRoles(roles []protos.NodeRole) []string {
formattedRoles := []string{}

for _, role := range roles {
formattedRoles = append(formattedRoles, formatRole(role))
}

return formattedRoles
}

func formatRole(role protos.NodeRole) string {
return role.String()
}

func renderTable(t table.Writer, format int) string {
if format == 0 {
return t.Render()
Expand Down
87 changes: 87 additions & 0 deletions cmd/writers/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package writers

import (
"reflect"
"testing"

"github.com/aerospike/avs-client-go/protos"
)

func Test_formatRole(t *testing.T) {
type args struct {
role protos.NodeRole
}
tests := []struct {
name string
args args
want string
}{
{
name: "TestRolePrimary",
args: args{role: protos.NodeRole_INDEX_QUERY},
want: "INDEX_QUERY",
},
{
name: "TestRoleSecondary",
args: args{role: protos.NodeRole_INDEX_UPDATE},
want: "INDEX_UPDATE",
},
{
name: "TestRoleUnknown",
args: args{role: protos.NodeRole_KV_READ},
want: "KV_READ",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := formatRole(tt.args.role); got != tt.want {
t.Errorf("formatRole() = %v, want %v", got, tt.want)
}
})
}
}

func Test_formatRoles(t *testing.T) {
type args struct {
roles []protos.NodeRole
}
tests := []struct {
name string
args args
want []string
}{
{
name: "TestMultipleRoles",
args: args{
roles: []protos.NodeRole{
protos.NodeRole_INDEX_QUERY,
protos.NodeRole_INDEX_UPDATE,
protos.NodeRole_KV_READ,
},
},
want: []string{"INDEX_QUERY", "INDEX_UPDATE", "KV_READ"},
},
{
name: "TestSingleRole",
args: args{roles: []protos.NodeRole{protos.NodeRole_INDEX_QUERY}},
want: []string{"INDEX_QUERY"},
},
{
name: "TestNoRoles",
args: args{roles: []protos.NodeRole{}},
want: []string{},
},
{
name: "TestNilRoles",
args: args{roles: nil},
want: []string{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := formatRoles(tt.args.roles); !reflect.DeepEqual(got, tt.want) {
t.Errorf("formatRoles() = %v, want %v", got, tt.want)
}
})
}
}
12 changes: 0 additions & 12 deletions docker/asvec.docker/bake.hcl
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
variable "VERSION_ARG" {
default = "0.0.0"
}

variable "REPO" {
default = "artifact.aerospike.io/ecosystem-container-dev-local"
}

group "default" {
targets = ["asvec"]
Expand All @@ -15,10 +8,5 @@ target "asvec" {
dockerfile = "./Dockerfile"
platforms = ["linux/amd64", "linux/arm64"]
tags = [
"${REPO}/asvec:${VERSION_ARG}",
"${REPO}/asvec:latest",
]
args = {
VERSION = "${VERSION_ARG}"
}
}
2 changes: 1 addition & 1 deletion docker/auth/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
timeout: 20s
retries: 20
avs:
image: aerospike/aerospike-vector-search:0.11.1
image: aerospike/aerospike-vector-search:1.0.0
depends_on:
aerospike:
condition: service_healthy
Expand Down
Loading

0 comments on commit 317d6e8

Please sign in to comment.