Skip to content

Commit

Permalink
Use callisto builder to build and publish docker images. (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitryhil authored Jan 13, 2025
1 parent 9bcb8df commit 157e586
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 138 deletions.
68 changes: 0 additions & 68 deletions .github/workflows/build.yml

This file was deleted.

26 changes: 26 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build and Push to DockerHub

on:
push:
branches:
- chains/coreum-v0.50.x

jobs:
build-publish-docker:
name: Build and Push to DockerHub
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and publish images
run: make release-images
31 changes: 0 additions & 31 deletions .github/workflows/release.yml

This file was deleted.

12 changes: 0 additions & 12 deletions Dockerfile

This file was deleted.

3 changes: 0 additions & 3 deletions Dockerfile.hasura

This file was deleted.

4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ build/amd64:
.PHONY: images
images:
$(BUILDER) images

.PHONY: release-images
release-images:
$(BUILDER) release/images
1 change: 0 additions & 1 deletion build/callisto/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
const (
repoPath = "."
binaryName = "callisto"
binaryPath = "bin/" + binaryName
)

// Build builds callisto in docker.
Expand Down
10 changes: 7 additions & 3 deletions build/callisto/image/Dockerfile.tmpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
FROM {{ .From }}

# TODO: This is needed because we use psql to load schema. If we do it in go we will be able to use basic image.
# This is needed because we use psql to load schema.
RUN apk update && apk add postgresql

ARG TARGETARCH
COPY {{ .Binary }} /{{ .Binary }}
WORKDIR /callisto
COPY {{ .BinaryPath }} /usr/bin/{{ .BinaryName }}
COPY {{ .DBSchemaPath }} /var/lib/postgresql/schema
RUN chmod a+rx /var/lib/postgresql && \
chmod a+rx /var/lib/postgresql/schema

ENTRYPOINT ["/{{ .Binary }}"]
CMD [ "{{ .BinaryName }}", "start" ]
8 changes: 7 additions & 1 deletion build/callisto/image/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ type Data struct {
// From is the tag of the base image
From string

// Binary is the path to the binary file
BinaryPath string

// Binary is the name of faucet binary file to copy from build context
Binary string
BinaryName string

// DBSchemaPath is the path to the database schema
DBSchemaPath string
}

// Execute executes dockerfile template and returns complete dockerfile.
Expand Down
37 changes: 31 additions & 6 deletions build/callisto/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,47 @@ import (
"github.com/CoreumFoundation/crust/build/types"
)

// BuildDockerImage builds docker image of the faucet.
// BuildDockerImage builds docker image.
func BuildDockerImage(ctx context.Context, deps types.DepsFunc) error {
return buildDockerImage(ctx, deps, false)
}

// ReleaseDockerImage releases docker image.
func ReleaseDockerImage(ctx context.Context, deps types.DepsFunc) error {
return buildDockerImage(ctx, deps, true)
}

func buildDockerImage(ctx context.Context, deps types.DepsFunc, push bool) error {
deps(Build)

dockerfile, err := image.Execute(image.Data{
From: docker.AlpineImage,
Binary: binaryPath,
From: docker.AlpineImage,
BinaryPath: filepath.Join("bin", ".cache", binaryName, tools.TargetPlatformLinuxLocalArchInDocker.String(), "bin", binaryName),
BinaryName: binaryName,
DBSchemaPath: filepath.Join("database", "schema"),
})
if err != nil {
return err
}

var action docker.Action
if push {
action = docker.ActionPush
} else {
action = docker.ActionLoad
}

return docker.BuildImage(ctx, docker.BuildImageConfig{
ContextDir: filepath.Join("bin", ".cache", binaryName, tools.TargetPlatformLinuxLocalArchInDocker.String()),
ImageName: binaryName,
ContextDir: ".",
ImageName: config.DockerHubUsername + "/" + binaryName,
TargetPlatforms: []tools.TargetPlatform{
tools.TargetPlatformLinuxAMD64InDocker,
tools.TargetPlatformLinuxARM64InDocker,
},
Dockerfile: dockerfile,
Versions: []string{config.ZNetVersion},
Action: action,
Versions: []string{
"latest",
},
})
}
1 change: 1 addition & 0 deletions build/hasura/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
FROM --platform=$TARGETPLATFORM hasura/graphql-engine:v2.35.0.cli-migrations-v3
COPY hasura hasura
WORKDIR hasura

29 changes: 26 additions & 3 deletions build/hasura/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,41 @@ import (

"github.com/CoreumFoundation/crust/build/config"
"github.com/CoreumFoundation/crust/build/docker"
"github.com/CoreumFoundation/crust/build/tools"
"github.com/CoreumFoundation/crust/build/types"
)

//go:embed Dockerfile
var dockerfile []byte

// BuildDockerImage builds docker image of the faucet.
// BuildDockerImage builds docker image.
func BuildDockerImage(ctx context.Context, deps types.DepsFunc) error {
return buildDockerImage(ctx, false)
}

// ReleaseDockerImage builds and releases docker image.
func ReleaseDockerImage(ctx context.Context, deps types.DepsFunc) error {
return buildDockerImage(ctx, true)
}

func buildDockerImage(ctx context.Context, push bool) error {
var action docker.Action
if push {
action = docker.ActionPush
} else {
action = docker.ActionLoad
}
return docker.BuildImage(ctx, docker.BuildImageConfig{
ContextDir: ".", // TODO (wojciech): Later on, move `hasura` dir here
ImageName: "hasura",
ImageName: config.DockerHubUsername + "/hasura",
TargetPlatforms: []tools.TargetPlatform{
tools.TargetPlatformLinuxAMD64InDocker,
tools.TargetPlatformLinuxARM64InDocker,
},
Dockerfile: dockerfile,
Versions: []string{config.ZNetVersion},
Action: action,
Versions: []string{
"latest",
},
})
}
10 changes: 6 additions & 4 deletions build/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ var Commands = map[string]types.Command{
deps(callisto.BuildDockerImage, hasura.BuildDockerImage)
return nil
}, Description: "Builds callisto and hasura docker images"},
"images/callisto": {Fn: callisto.BuildDockerImage, Description: "Builds callisto image"},
"images/hasura": {Fn: hasura.BuildDockerImage, Description: "Builds hasura docker image"},
"test": {Fn: golang.Test, Description: "Runs unit tests"},
"tidy": {Fn: golang.Tidy, Description: "Runs go mod tidy"},
"release/images": {Fn: func(ctx context.Context, deps types.DepsFunc) error {
deps(callisto.ReleaseDockerImage, hasura.ReleaseDockerImage)
return nil
}, Description: "Builds callisto and hasura docker images and releases them"},
"test": {Fn: golang.Test, Description: "Runs unit tests"},
"tidy": {Fn: golang.Tidy, Description: "Runs go mod tidy"},
}
8 changes: 4 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
- "5432:5432"

hasura:
image: hasura:znet
image: coreumfoundation/hasura:latest
ports:
- "8080:8080"
restart: always
Expand All @@ -43,9 +43,9 @@ services:
ACTION_BASE_URL: http://callisto:3000

callisto:
image: callisto:znet
image: coreumfoundation/callisto:latest
restart: always
command: callisto parse --home /callisto/.callisto
command: callisto start --home /callisto/.callisto
volumes:
## Modify first path to match configuration file.
- /callisto/.callisto:/callisto/.callisto
- .callisto:/callisto/.callisto
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ replace (
// dgrijalva/jwt-go is deprecated and doesn't receive security updates.
// TODO(v5): remove it: https://github.com/cosmos/cosmos-sdk/issues/13134
github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2
// Coreum verison of the juno
github.com/forbole/juno/v6 => github.com/CoreumFoundation/juno/v6 v6.0.0-20241216105105-8b46c0519796
// Fix upstream GHSA-h395-qcrw-5vmq vulnerability.
// TODO(v5) Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbi
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/CoreumFoundation/coreum/v5 v5.0.0-20241218110558-764cbf9da77f h1:VvjluQ/VwZZcmkaecn3R79CFJBz6Z2/KNTKsqyhgoak=
github.com/CoreumFoundation/coreum/v5 v5.0.0-20241218110558-764cbf9da77f/go.mod h1:zCEOLCDyZGbkwqIfvfHD8U46xlSwaktweHaY22Ac2rM=
github.com/CoreumFoundation/juno/v6 v6.0.0-20241216105105-8b46c0519796 h1:5yENI7YHgxQQpcGSIppOTAXfjqjQEQG9qljqchGTgdo=
github.com/CoreumFoundation/juno/v6 v6.0.0-20241216105105-8b46c0519796/go.mod h1:O3o+73CiNjsIuPNWBOH3Wv59vvI5zeGfYIZBjsNj4/I=
github.com/CosmWasm/wasmd v0.53.0 h1:kdaoAi20bIb4VCsxw9pRaT2g5PpIp82Wqrr9DRVN9ao=
github.com/CosmWasm/wasmd v0.53.0/go.mod h1:FJl/aWjdpGof3usAMFQpDe07Rkx77PUzp0cygFMOvtw=
github.com/CosmWasm/wasmvm/v2 v2.1.2 h1:GkJ5bAsRlLHfIQVg/FY1VHwLyBwlCjAhDea0B8L+e20=
Expand Down Expand Up @@ -349,8 +351,6 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/firefart/nonamedreturns v1.0.4 h1:abzI1p7mAEPYuR4A+VLKn4eNDOycjYo2phmY9sfv40Y=
github.com/firefart/nonamedreturns v1.0.4/go.mod h1:TDhe/tjI1BXo48CmYbUduTV7BdIga8MAO/xbKdcVsGI=
github.com/forbole/juno/v6 v6.0.1 h1:oOoHU+X/7YjKaGce8xtuT1xS9jF1czhvLr3OCH1ipPo=
github.com/forbole/juno/v6 v6.0.1/go.mod h1:O3o+73CiNjsIuPNWBOH3Wv59vvI5zeGfYIZBjsNj4/I=
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=
Expand Down

0 comments on commit 157e586

Please sign in to comment.