runner: update deploy workflow to push docker image to registry and deploy using docker compose

This commit is contained in:
Tigor Hutasuhut 2024-05-11 22:02:04 +07:00
parent 0498985f51
commit e1147efbd9
5 changed files with 24 additions and 15 deletions

View file

@ -1,9 +1,7 @@
# on: on:
# push: push:
# tags: tags:
# - "v*" - "v*.*.*"
on: [push]
jobs: jobs:
deploy: deploy:
@ -12,4 +10,9 @@ jobs:
image: docker:26.1.2 image: docker:26.1.2
steps: steps:
- run: echo "Testing ${{ github.ref_name }}" - run: echo "Deploying version ${{ github.ref_name }}"
- run: docker build -t git.tigor.web.id/tigor/redmage:${{ github.ref_name }} .
- run: docker build -t git.tigor.web.id/tigor/redmage:latest .
- run: docker push git.tigor.web.id/tigor/redmage:${{ github.ref_name }}
- run: docker push git.tigor.web.id/tigor/redmage:latest
- run: docker compose up -d

View file

@ -15,8 +15,8 @@ COPY go.mod go.sum ./
RUN go mod download RUN go mod download
COPY . . COPY . .
COPY --from=web-builder /web/public ./public COPY --from=web-builder /web/public ./public
RUN --mount=type=cache,target=/root/.cache/go-build \ ENV REDMAGE_RUNTIME_VERSION=unknown
./bin/templ generate && GOOS=linux GOARCH=amd64 go build -o /app/redmage main.go RUN --mount=type=cache,target=/root/.cache/go-build make build-docker
FROM gcr.io/distroless/base:nonroot FROM gcr.io/distroless/base:nonroot

View file

@ -10,10 +10,9 @@ export GOOSE_MIGRATION_DIR=db/migrations
export REDMAGE_WEB_DEPENDENCIES_HTMX_VERSION=$(shell echo "$${REDMAGE_WEB_DEPENDENCIES_HTMX_VERSION:-1.9.12}") export REDMAGE_WEB_DEPENDENCIES_HTMX_VERSION=$(shell echo "$${REDMAGE_WEB_DEPENDENCIES_HTMX_VERSION:-1.9.12}")
export REDMAGE_WEB_DEPENDENCIES_DAYJS_VERSION=$(shell echo "$${REDMAGE_WEB_DEPENDENCIES_DAYJS_VERSION:-1.11.10}") export REDMAGE_WEB_DEPENDENCIES_DAYJS_VERSION=$(shell echo "$${REDMAGE_WEB_DEPENDENCIES_DAYJS_VERSION:-1.11.10}")
export REDMAGE_WEB_DEPENDENCIES_ALPINEJS_VERSION=$(shell echo "$${REDMAGE_WEB_DEPENDENCIES_ALPINEJS_VERSION:-3.13.10}") export REDMAGE_WEB_DEPENDENCIES_ALPINEJS_VERSION=$(shell echo "$${REDMAGE_WEB_DEPENDENCIES_ALPINEJS_VERSION:-3.13.10}")
export REDMAGE_RUNTIME_VERSION=$(shell echo "$${REDMAGE_RUNTIME_VERSION:-unknown}")
start: dev-dependencies start: dev-dependencies
@tailwindcss -i views/style.css -o public/style.css --watch &
@templ generate -watch &
air air
dev-dependencies: build-dependencies dev-dependencies: build-dependencies
@ -83,8 +82,11 @@ web-build: web-dependencies
build: web-dependencies build-dependencies prepare build: web-dependencies build-dependencies prepare
go build -o redmage go build -o redmage
build-docker: migrate-up build-docker:
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o redmage goose up
templ generate
go run github.com/stephenafamo/bob/gen/bobgen-sqlite@latest
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X 'github.com/tigorlazuardi/redmage/config.Version=${REDMAGE_RUNTIME_VERSION}'" -o redmage
prepare: gen prepare: gen
mkdir -p public mkdir -p public

View file

@ -6,6 +6,8 @@ import (
"github.com/adrg/xdg" "github.com/adrg/xdg"
) )
var Version string = "unknown"
var DefaultConfig = map[string]any{ var DefaultConfig = map[string]any{
"flags.containerized": false, "flags.containerized": false,
@ -60,6 +62,6 @@ var DefaultConfig = map[string]any{
"web.dependencies.dayjs.version": "1.11.10", "web.dependencies.dayjs.version": "1.11.10",
"web.dependencies.alpinejs.version": "3.13.10", "web.dependencies.alpinejs.version": "3.13.10",
"runtime.version": "0.0.1", "runtime.version": Version,
"runtime.environment": "development", "runtime.environment": "development",
} }

View file

@ -27,8 +27,10 @@ func (srv *Server) Start(exit <-chan struct{}) error {
caller := caller.New(3) caller := caller.New(3)
go func() { go func() {
log.New(context.Background()).Caller(caller).Info( log.New(context.Background()).Caller(caller).Info(
"starting http server", "address", "http://"+srv.server.Addr, "starting http server",
"address", "http://"+srv.server.Addr,
"outbound_ip", "http://"+GetOutboundIP().String()+":"+srv.config.String("http.port"), "outbound_ip", "http://"+GetOutboundIP().String()+":"+srv.config.String("http.port"),
"version", srv.config.String("runtime.version"),
) )
errch <- srv.server.ListenAndServe() errch <- srv.server.ListenAndServe()
}() }()