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
107 changes: 14 additions & 93 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,100 +1,21 @@
name: Build docker image
---
name: Build and Publish Docker Image

on:
push:
tags:
- "v*"
branches:
- "*"

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
release:
types:
- published

jobs:
build-and-push-image:
runs-on: ubuntu-22.04
if: "${{ !startsWith(github.event.head_commit.message, 'GitBook: [#') }}"

outputs:
image: ${{ steps.meta.outputs.image }}
tags: ${{ steps.meta.outputs.tags }}

build:
uses: ICN-Protocol/github-common/.github/workflows/build-docker.yml@v0.4.2
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Generate docker tags/labels from github build context
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=tag
type=sha,prefix=
type=raw,enable=${{ github.ref == 'refs/heads/develop' }},value=develop
type=edge,branch=develop
flavor: |
latest=${{ startsWith(github.ref, 'refs/tags/') }}

- name: Extract version
id: extract-version
run: |
version=edge
commit_date="$(git show -s --format=%cI)"
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
version=${GITHUB_REF#refs/tags/}
fi

echo "VERSION=$version (Commit ${GITHUB_SHA::7}, Commit Date $commit_date)" >> "$GITHUB_OUTPUT"

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ steps.extract-version.outputs.VERSION }}

slack-notifications:
if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }}
needs: [build-and-push-image]
runs-on: ubuntu-22.04
steps:
- name: Slack notification
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
uses: Ilshidur/action-slack@2.0.2
with:
args: |
:done: *${{ github.repository }}* Success building docker images from ${{ github.ref_type }} _${{ github.ref_name }}_ (${{ github.actor }}) :sparkling_heart: ```${{ join(needs.build-and-push-image.outputs.tags, ' ') }}
${{ needs.build-and-push-image.outputs.image }}```
with:
imageName: ${{ github.event.repository.name }}
push: true
file: ./Dockerfile
secrets:
token: ${{ secrets.GIT_TOKEN }}
password: ${{ secrets.GITHUB_TOKEN }}
20 changes: 14 additions & 6 deletions db_proto/sql/postgres/accumulator_inserter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
)

type accumulator struct {
query string
rowValues [][]string
query string
fieldsCount int
rowValues [][]string
}

type AccumulatorInserter struct {
Expand All @@ -34,12 +35,13 @@ func (i *AccumulatorInserter) init(database *Database) error {
accumulators := map[string]*accumulator{}

for _, table := range tables {
query, err := createInsertFromDescriptorAcc(table, database.dialect)
query, fieldsCount, err := createInsertFromDescriptorAcc(table, database.dialect)
if err != nil {
return fmt.Errorf("creating insert from descriptor for table %q: %w", table.Name, err)
}
accumulators[table.Name] = &accumulator{
query: query,
query: query,
fieldsCount: fieldsCount,
}
}
accumulators["_blocks_"] = &accumulator{
Expand All @@ -58,7 +60,7 @@ func (i *AccumulatorInserter) init(database *Database) error {
return nil
}

func createInsertFromDescriptorAcc(table *schema.Table, dialect sql2.Dialect) (string, error) {
func createInsertFromDescriptorAcc(table *schema.Table, dialect sql2.Dialect) (string, int, error) {
tableName := dialect.FullTableName(table)
fields := table.Columns

Expand Down Expand Up @@ -95,11 +97,12 @@ func createInsertFromDescriptorAcc(table *schema.Table, dialect sql2.Dialect) (s
return fmt.Sprintf("INSERT INTO %s (%s) VALUES ",
tableName,
strings.Join(fieldNames, ", "),
), nil
), len(fieldNames), nil

}

func (i *AccumulatorInserter) insert(table string, values []any, database *Database) error {

var v []string
if table == "_cursor_" {
stmt := database.wrapInsertStatement(i.cursorStmt)
Expand All @@ -116,6 +119,11 @@ func (i *AccumulatorInserter) insert(table string, values []any, database *Datab
if accumulator == nil {
return fmt.Errorf("accumulator not found for table %q", table)
}

for i := 0; i < accumulator.fieldsCount-len(v); i++ {
v = append(v, "NULL")
}

accumulator.rowValues = append(accumulator.rowValues, v)

return nil
Expand Down
Loading