Skip to content

Commit ab790ce

Browse files
authored
Add Docker file and worflow to build image (#125)
1 parent 4be29a0 commit ab790ce

File tree

3 files changed

+123
-2
lines changed

3 files changed

+123
-2
lines changed

.github/workflows/docker.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Docker Image
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: 'Tag'
8+
required: true
9+
release:
10+
types: [created]
11+
12+
env:
13+
REGISTRY: ghcr.io
14+
IMAGE_NAME: ${{ github.repository }}
15+
VERSION: ${{ github.event.inputs.tag || github.event.release.tag_name || '' }}
16+
17+
jobs:
18+
build-and-push:
19+
runs-on: k8s-infrastructure-dind
20+
21+
permissions:
22+
contents: read
23+
packages: write
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
29+
- name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v3
31+
32+
- name: Log in to the Container registry
33+
uses: docker/login-action@v3
34+
with:
35+
registry: ${{ env.REGISTRY }}
36+
username: ${{ github.actor }}
37+
password: ${{ secrets.GITHUB_TOKEN }}
38+
39+
- name: Check if VERSION follows the x.x.x format
40+
run: |
41+
if [[ "${{ env.VERSION }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
42+
echo "LATEST_TAG_ENABLED=true" >> $GITHUB_ENV
43+
else
44+
echo "LATEST_TAG_ENABLED=false" >> $GITHUB_ENV
45+
fi
46+
47+
- name: Extract metadata (tags, labels) for Docker
48+
id: meta
49+
uses: docker/metadata-action@v5
50+
with:
51+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
52+
tags: |
53+
type=sha
54+
type=semver,pattern={{version}},value=${{ env.VERSION }}
55+
type=raw,value=latest,enable=${{ env.LATEST_TAG_ENABLED == 'true' }}
56+
type=raw,value=testnet
57+
flavor: |
58+
latest=false
59+
60+
- name: Build and push Docker image
61+
id: push
62+
uses: docker/build-push-action@v5
63+
with:
64+
context: .
65+
platforms: linux/amd64,linux/arm64
66+
push: true
67+
tags: ${{ steps.meta.outputs.tags }}
68+
labels: ${{ steps.meta.outputs.labels }}
69+
cache-from: type=gha
70+
cache-to: type=gha,mode=max
71+
build-args: |
72+
VERSION=${{ env.VERSION }}

Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM golang:alpine as build
2+
ARG VERSION
3+
4+
RUN apk add --no-cache git build-base
5+
6+
WORKDIR /app
7+
8+
# Generate build.info file
9+
RUN echo "version: ${VERSION}" > build.info && \
10+
echo "build_time: $(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> build.info
11+
12+
# Copy go mod and sum files
13+
COPY go.mod go.sum ./
14+
15+
# Copy the source code
16+
COPY . .
17+
18+
# Build the application
19+
RUN CGO_ENABLED=0 go build -o app .
20+
21+
FROM alpine:3.17
22+
23+
WORKDIR /app
24+
25+
RUN apk add --no-cache ca-certificates curl
26+
27+
COPY --from=build /app/build.info /version
28+
COPY --from=build /app/app /app/app
29+

cmd/keys.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,45 @@ type Config struct {
4040

4141
// GenerateKeysCmd generates a new key pair and attempts to save it to the file
4242
func GenerateKeysCmd() *cobra.Command {
43+
var accountID string
44+
var outputPath string
45+
4346
generateKey := &cobra.Command{
4447
Use: "generate-key",
4548
Short: "Command to generate signer key pair",
4649
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
47-
return bindConfiguration(cmd)
50+
if accountID == "" {
51+
return bindConfiguration(cmd)
52+
}
53+
return nil
4854
},
4955

5056
RunE: func(cmd *cobra.Command, args []string) error {
57+
if accountID != "" {
58+
if outputPath == "" {
59+
fmt.Println("Please provide output path using --output flag")
60+
os.Exit(1)
61+
}
62+
key := newKey(accountID)
63+
dumpJson(outputPath, key)
64+
fmt.Printf("key generated: [%s]", outputPath)
65+
return nil
66+
}
67+
5168
config := loadConfig()
52-
key := newKey("")
5369
if config.SignerKey == "" {
5470
fmt.Println("signerKey is not set, please provide it in the config file")
5571
os.Exit(1)
5672
}
73+
key := newKey("")
5774
dumpJson(config.SignerKey, key)
5875
fmt.Printf("key generated: [%s]", config.SignerKey)
5976
return nil
6077
},
6178
}
79+
80+
generateKey.Flags().StringVar(&accountID, "account-id", "", "Account ID to generate key for")
81+
generateKey.Flags().StringVar(&outputPath, "output", "", "Output path for the generated key when using --account-id")
6282
acceptConfigFilePath(generateKey)
6383
return generateKey
6484
}

0 commit comments

Comments
 (0)