chore: add config.version, docker image building in make and others

This commit is contained in:
Максим Слипенко 2024-12-17 18:48:10 +03:00
parent 1a7d9ea797
commit 33e51735cf
7 changed files with 28 additions and 7 deletions

View file

@ -1,4 +1,3 @@
# Первый этап: сборка приложения
FROM golang:latest AS builder
WORKDIR /app
@ -6,9 +5,8 @@ WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go build -o aides-repo-api ./cmd/aides-repo-api/main.go
RUN make build
# Второй этап: создание финального образа
FROM registry.altlinux.org/sisyphus/alt:20241211
RUN \

View file

@ -1,7 +1,14 @@
GIT_VERSION = $(shell git describe --tags )
GOLANGCI_LINT := go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2
SWAG := go run github.com/swaggo/swag/cmd/swag@v1.16.4
format:
@echo "🛠️ Format and Lint code with golangci-lint"
$(GOLANGCI_LINT) run
$(SWAG) fmt
@echo "✅ Format and Lint done."
format-fix:
@echo "🛠️ Format and Lint code with golangci-lint"
$(GOLANGCI_LINT) run --fix
$(SWAG) fmt
@ -10,4 +17,13 @@ format:
swag:
$(SWAG) init -g cmd/aides-repo-api/main.go
build:
go build \
-ldflags="-X 'code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config.Version=$(GIT_VERSION)'" \
-o aides-repo-api \
./cmd/aides-repo-api/main.go
build-docker:
docker build -t ghcr.io/aides-infra/aides-repo-api .
.PHONY: format swag

View file

@ -71,7 +71,7 @@ const docTemplate = `{
"application/json"
],
"tags": [
"tasks"
"Tasks"
],
"summary": "Upload files to a task",
"parameters": [

View file

@ -60,7 +60,7 @@
"application/json"
],
"tags": [
"tasks"
"Tasks"
],
"summary": "Upload files to a task",
"parameters": [

View file

@ -117,5 +117,5 @@ paths:
$ref: '#/definitions/errors.ErrResponse'
summary: Upload files to a task
tags:
- tasks
- Tasks
swagger: "2.0"

View file

@ -0,0 +1,3 @@
package config
var Version = "unknown"

View file

@ -4,7 +4,7 @@ import (
"github.com/go-chi/chi/v5"
httpSwagger "github.com/swaggo/http-swagger"
_ "code.alt-gnome.ru/aides-infra/aides-repo-api/docs"
docs "code.alt-gnome.ru/aides-infra/aides-repo-api/docs"
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/config"
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/controllers/taskcontroller"
"code.alt-gnome.ru/aides-infra/aides-repo-api/internal/logger"
@ -33,6 +33,10 @@ func (r *Router) Setup() *chi.Mux {
router := chi.NewRouter()
router.Use(logger)
docs.SwaggerInfo.Title = "Aides Repo API"
docs.SwaggerInfo.Version = config.Version
docs.SwaggerInfo.BasePath = "/"
docs.SwaggerInfo.Schemes = []string{"https"}
router.Get("/swagger/*", httpSwagger.WrapHandler)
router.Route("/tasks", func(taskRouter chi.Router) {