setup docker volumes & versions

This commit is contained in:
Hayden 2022-09-13 21:15:01 -08:00
parent 0b92d57b85
commit 1dc9d6396a
7 changed files with 35 additions and 16 deletions

View file

@ -64,6 +64,7 @@ jobs:
docker build --push \ docker build --push \
--tag ghcr.io/hay-kot/homebox:nightly \ --tag ghcr.io/hay-kot/homebox:nightly \
--build-arg COMMIT=$(git rev-parse HEAD) \ --build-arg COMMIT=$(git rev-parse HEAD) \
--build-arg BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
--platform linux/amd64,linux/arm64,linux/arm/v7 . --platform linux/amd64,linux/arm64,linux/arm/v7 .
deploy-docs: deploy-docs:

View file

@ -1,3 +1,4 @@
# Build Nuxt # Build Nuxt
FROM node:17-alpine as frontend-builder FROM node:17-alpine as frontend-builder
WORKDIR /app WORKDIR /app
@ -6,27 +7,31 @@ COPY frontend/package.json frontend/pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile --shamefully-hoist RUN pnpm install --frozen-lockfile --shamefully-hoist
COPY frontend . COPY frontend .
RUN pnpm build RUN pnpm build
RUN ls -la /app/.output/
# Build API # Build API
FROM golang:alpine AS builder FROM golang:alpine AS builder
RUN apk update ARG BUILD_TIME
RUN apk upgrade ARG COMMIT
RUN apk add --update git build-base gcc g++ RUN apk update && \
apk upgrade && \
apk add --update git build-base gcc g++
WORKDIR /go/src/app WORKDIR /go/src/app
COPY ./backend . COPY ./backend .
RUN go get -d -v ./... RUN go get -d -v ./...
RUN rm -rf ./app/api/public RUN rm -rf ./app/api/public
COPY --from=frontend-builder /app/.output/public ./app/api/public COPY --from=frontend-builder /app/.output/public ./app/api/public
RUN CGO_ENABLED=1 GOOS=linux go build \ RUN CGO_ENABLED=1 GOOS=linux go build \
-ldflags "-s -w -X main.Commit=$COMMIT -X main.BuildTime=$BUILD_TIME" \
-o /go/bin/api \ -o /go/bin/api \
-v ./app/api/*.go \ -v ./app/api/*.go
-ldflags "-s -w -X main.Commit `git rev-parse HEAD` -X main.BuildTime `date -u +%Y-%m-%dT%H:%M:%SZ`"
# Production Stage # Production Stage
FROM alpine:latest FROM alpine:latest
RUN apk --no-cache add ca-certificates RUN apk --no-cache add ca-certificates
COPY ./backend/config.template.yml /app/config.yml COPY ./backend/config.template.yml /data/config.yml
RUN mkdir /app
COPY --from=builder /go/bin/api /app COPY --from=builder /go/bin/api /app
RUN chmod +x /app/api RUN chmod +x /app/api
@ -34,4 +39,7 @@ RUN chmod +x /app/api
LABEL Name=homebox Version=0.0.1 LABEL Name=homebox Version=0.0.1
EXPOSE 7745 EXPOSE 7745
WORKDIR /app WORKDIR /app
CMD [ "./api" ] VOLUME [ "/data" ]
ENTRYPOINT [ "/app/api" ]
CMD [ "/data/config.yml" ]

View file

@ -60,10 +60,10 @@
- [ ] Contributors Guide - [ ] Contributors Guide
- [x] Security Policy - [x] Security Policy
- [ ] Feature Request Template - [ ] Feature Request Template
- [ ] Embedded Version Info - [x] Embedded Version Info
- [ ] Version Number - [x] Version Number
- [ ] Git Has - [x] Git Hash
- [ ] Setup Docker Volumes in Dockerfile - [x] Setup Docker Volumes in Dockerfile
## All Todo's ## All Todo's

View file

@ -20,7 +20,7 @@ tasks:
api: api:
cmds: cmds:
- task: generate - task: generate
- cd backend && go run ./app/api/ {{.CLI_ARGS}} - cd backend && go run ./app/api/ {{.CLI_ARGS}} ./config.yml
silent: false silent: false
api:build: api:build:

View file

@ -2,6 +2,7 @@ package main
import ( import (
"context" "context"
"os"
"time" "time"
"github.com/hay-kot/content/backend/app/api/docs" "github.com/hay-kot/content/backend/app/api/docs"
@ -31,10 +32,16 @@ var (
// @name Authorization // @name Authorization
// @description "Type 'Bearer TOKEN' to correctly set the API Key" // @description "Type 'Bearer TOKEN' to correctly set the API Key"
func main() { func main() {
path := ""
if len(os.Args) > 1 {
path = os.Args[1]
}
cfgFile := "config.yml" if path == "" {
log.Warn().Msg("No configuration detected, using defaults")
}
cfg, err := config.NewConfig(cfgFile) cfg, err := config.NewConfig(path)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View file

@ -14,5 +14,5 @@ type ApiSummary struct {
type Build struct { type Build struct {
Version string `json:"version"` Version string `json:"version"`
Commit string `json:"commit"` Commit string `json:"commit"`
BuildTime string `json:"build_time"` BuildTime string `json:"buildTime"`
} }

View file

@ -6,5 +6,8 @@ services:
build: build:
context: . context: .
dockerfile: ./Dockerfile dockerfile: ./Dockerfile
args:
- COMMIT=head
- BUILD_TIME=0001-01-01T00:00:00Z
ports: ports:
- 3100:7745 - 3100:7745