Skip to content

Commit

Permalink
feat: include build info in docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwep committed Nov 2, 2023
1 parent ae85d3b commit 4f2c734
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ jobs:
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern=v{{version}}
type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -68,3 +68,7 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
build-args: |
GENESIS_BUILD_VERSION=${{ github.ref_name }}
GENESIS_BUILD_COMMIT=${{ github.sha }}
GENESIS_BUILD_DATE=${{ github.event.head_commit.timestamp }}
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@ RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build

FROM alpine:3.18

ARG GENESIS_BUILD_VERSION
ARG GENESIS_BUILD_DATE
ARG GENESIS_BUILD_COMMIT

WORKDIR /app

COPY --from=build /app/genesis /app

EXPOSE 8080

ENV GENESIS_BUILD_VERSION=${GENESIS_BUILD_VERSION}
ENV GENESIS_BUILD_DATE=${GENESIS_BUILD_DATE}
ENV GENESIS_BUILD_COMMIT=${GENESIS_BUILD_COMMIT}

CMD ["./genesis"]
18 changes: 16 additions & 2 deletions core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ type AppConfig struct {
DbPath string
JWTSecret []byte
JWTExpiration time.Duration
AppBuildVersion string
AppBuildDate string
AppBuildCommit string
AppGinMode string
AppLogMode string
AppPort string
Expand All @@ -36,13 +39,16 @@ var Config = func() AppConfig {
}

if err := godotenv.Load(envFile); err != nil {
Logger.Info(".env file not found", zap.Error(err))
Logger.Info(".env file skipped")
}

return AppConfig{
config := AppConfig{
DbPath: resolvePath(os.Getenv("GENESIS_DB_PATH")),
JWTSecret: []byte(os.Getenv("GENESIS_JWT_SECRET")),
JWTExpiration: time.Duration(parseInt(os.Getenv("GENESIS_JWT_TOKEN_EXPIRATION"))) * time.Minute,
AppBuildVersion: os.Getenv("GENESIS_BUILD_VERSION"),
AppBuildDate: os.Getenv("GENESIS_BUILD_DATE"),
AppBuildCommit: os.Getenv("GENESIS_BUILD_COMMIT"),
AppGinMode: os.Getenv("GENESIS_GIN_MODE"),
AppLogMode: os.Getenv("GENESIS_LOG_MODE"),
AppPort: os.Getenv("GENESIS_PORT"),
Expand All @@ -52,6 +58,14 @@ var Config = func() AppConfig {
AppDataMaxSize: parseInt(os.Getenv("GENESIS_DATA_MAX_SIZE")) * 1000,
AppKeysPerUser: parseInt(os.Getenv("GENESIS_KEYS_PER_USER")),
}

Logger.Info("build info",
zap.String("version", config.AppBuildVersion),
zap.String("date", config.AppBuildDate),
zap.String("commit", config.AppBuildCommit),
)

return config
}()

func parseInitialUserList(raw string) []User {
Expand Down

0 comments on commit 4f2c734

Please sign in to comment.