Skip to content

Commit

Permalink
Merge pull request #57 from deco-finter/ci/version-embed
Browse files Browse the repository at this point in the history
Version embed
  • Loading branch information
daystram committed Oct 5, 2021
2 parents 5f5c891 + 04d7306 commit f087edd
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 4 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,22 @@ jobs:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Set Development Version
run: echo "RELEASE_VERSION=v0.0.0-development" >> $GITHUB_ENV
run: |
export RELEASE_VERSION="v0.0.0-development"
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV
echo "RELEASE_VERSION_LONG=${RELEASE_VERSION}:${GITHUB_REF#refs/heads/}@${GITHUB_SHA:0:7}" >> $GITHUB_ENV
- name: Provide Env File
run: |
echo "${{ secrets.FE_ENV_FILE }}" > ${{ env.APPLICATION }}-${{ matrix.service }}/.env.production
echo "REACT_APP_VERSION=${{ env.RELEASE_VERSION }}:${GITHUB_REF#refs/heads/}@${GITHUB_SHA:0:7}" >> ${{ env.APPLICATION }}-${{ matrix.service }}/.env.production
echo "REACT_APP_VERSION=${{ env.RELEASE_VERSION_LONG }}" >> ${{ env.APPLICATION }}-${{ matrix.service }}/.env.production
- name: Build and Push Image
uses: docker/build-push-action@v2
with:
context: .
file: ${{ env.APPLICATION }}-${{ matrix.service }}/Dockerfile
platforms: linux/amd64
build-args: |
VERSION=${{ env.RELEASE_VERSION_LONG }}
tags: daystram/${{ env.APPLICATION }}:${{ matrix.service }}-dev
push: true
chart:
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ jobs:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Get Release Version
run: echo "RELEASE_VERSION=${GITHUB_REF##*/}" >> $GITHUB_ENV
run: |
export RELEASE_VERSION="${GITHUB_REF##*/}"
echo "RELEASE_VERSION=${RELEASE_VERSION}" >> $GITHUB_ENV
echo "RELEASE_VERSION_LONG=${RELEASE_VERSION}:${GITHUB_REF#refs/heads/}@${GITHUB_SHA:0:7}" >> $GITHUB_ENV
- name: Provide Env File
run: |
echo "${{ secrets.FE_ENV_FILE }}" > ${{ env.APPLICATION }}-${{ matrix.service }}/.env.production
Expand All @@ -39,6 +42,8 @@ jobs:
context: .
file: ${{ env.APPLICATION }}-${{ matrix.service }}/Dockerfile
platforms: linux/amd64
build-args: |
VERSION=${{ env.RELEASE_VERSION }}
tags: |
daystram/${{ env.APPLICATION }}:${{ matrix.service }}
daystram/${{ env.APPLICATION }}:${{ matrix.service }}-${{ env.RELEASE_VERSION }}
Expand Down
3 changes: 2 additions & 1 deletion fableous-be/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
FROM daystram/go-builder:1.16 as builder
ARG VERSION=v0.0.0-development
WORKDIR /build
COPY fableous-be fableous-be
COPY proto proto
COPY Makefile .
RUN make be
WORKDIR /build/fableous-be
RUN go mod tidy
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -o app .
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-X 'main.version=${VERSION}'" -a -installsuffix nocgo -o app .

FROM alpine:latest
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
Expand Down
1 change: 1 addition & 0 deletions fableous-be/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
var AppConfig Config

type Config struct {
Version string
Port int
Environment string
Debug bool
Expand Down
1 change: 1 addition & 0 deletions fableous-be/controllers/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func InitializeRouter() (router *gin.Engine) {
)
api := router.Group("/api")
{
api.GET("/ping", GETPing)
auth := api.Group("/auth")
{
auth.POST("/login", POSTLogin)
Expand Down
13 changes: 13 additions & 0 deletions fableous-be/controllers/ping.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package controllers

import (
"net/http"

"github.com/gin-gonic/gin"

"github.com/deco-finter/fableous/fableous-be/config"
)

func GETPing(c *gin.Context) {
c.JSON(http.StatusOK, map[string]string{"version": config.AppConfig.Version})
}
6 changes: 6 additions & 0 deletions fableous-be/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ import (
"github.com/deco-finter/fableous/fableous-be/handlers"
)

var (
version string
)

func init() {
log.Printf("[INIT] starting fableous-be %s", version)
config.InitializeAppConfig()
config.AppConfig.Version = version
if !config.AppConfig.Debug {
gin.SetMode(gin.ReleaseMode)
}
Expand Down

0 comments on commit f087edd

Please sign in to comment.