Added base woodpecker task
Some checks failed
ci/woodpecker/push/workflow Pipeline failed

This commit is contained in:
2025-11-03 15:02:49 +01:00
parent 7fdb902a11
commit db831f7cb0
9 changed files with 276 additions and 112 deletions

View File

@@ -1,67 +0,0 @@
kind: pipeline
type: docker
name: default
steps:
- name: static_check
image: golang:latest
commands:
- go install honnef.co/go/tools/cmd/staticcheck@latest
- cd src && staticcheck ./...
volumes:
- name: gopath
path: /go
- name: lint
image: golang:latest
commands:
- go install golang.org/x/lint/golint@latest
- golint ./src/...
volumes:
- name: gopath
path: /go
- name: analyze
image: golang:latest
commands:
- cd src && go vet ./...
volumes:
- name: gopath
path: /go
- name: publish_image
image: plugins/docker
environment:
DOCKER_USERNAME:
from_secret: registry_username
DOCKER_PASSWORD:
from_secret: registry_password
commands:
- sleep 5
- ./deploy/image-build.sh
- ./deploy/image-push.sh
volumes:
- name: docker-sock
path: /var/run
when:
branch:
- main
services:
- name: docker
image: docker:dind
privileged: true
volumes:
- name: docker-sock
path: /var/run
- name: etc_hosts
path: /etc/hosts
volumes:
- name: gopath
temp: {}
- name: docker-sock
temp: {}
- name: etc_hosts
host:
path: /etc/hosts

143
.woodpecker/workflow.yaml Normal file
View File

@@ -0,0 +1,143 @@
variables:
- &golang_image 'docker.io/golang:1.24'
- &buildx_plugin 'docker.io/woodpeckerci/plugin-docker-buildx:6.0.3'
- &platforms_release 'linux/amd64'
- &build_args 'CI_COMMIT_SHA=${CI_COMMIT_SHA},CI_COMMIT_BRANCH=${CI_COMMIT_BRANCH},CI_COMMIT_TAG=${CI_COMMIT_TAG}'
- publish_logins: &publish_logins
- registry: git.ego.freeddns.org
secrets: [docker_username, docker_password]
username:
from_secret: docker_username
password:
from_secret: docker_password
when:
- event: [pull_request, tag]
- event: push
# branch: ${CI_REPO_DEFAULT_BRANCH}
branch: develop
steps:
# - name: analyze
# image: golang:1.24
# commands:
# - echo "Analyze"
# - cd src && go vet ./...
# - name: static check
# image: golang:1.24
# commands:
# - echo "Static Check"
# - go install honnef.co/go/tools/cmd/staticcheck@latest
# - cd src && staticcheck ./...
# - name: lint
# image: golang:1.24
# commands:
# - echo "Lint"
# - go install golang.org/x/lint/golint@latest
# - golint ./src/...
- name: vendor
image: *golang_image
pull: true
commands:
- cd src/
- go mod vendor
when:
- branch:
- develop
- name: build image
depends_on:
- vendor
image: woodpeckerci/plugin-docker-buildx
# settings:
# repo: git.ego.freeddns.org/egommerce/catalog-svc
# dockerfile: deploy/docker/Dockerfile.target
# tag: dev
# logins: *publish_logins
commands:
# - sleep 5
- export BUILDER_IMAGE="egommerce-builder:catalog"
- docker buildx --rm -t "$BUILDER_IMAGE" -f deploy/docker/Dockerfile.builder .
# - name: push image
# image: woodpeckerci/plugin-docker-buildx
# commands:
# - export BUILDER_IMAGE="egommerce-builder:catalog"
# - docker build \
# --build-arg SVC_NAME=catalog-svc \
# --build-arg SVC_VER="dev" \
# --build-arg BUILDER_IMAGE=$BUILDER_IMAGE \
# --build-arg BUILD_TIME \
# --rm --no-cache -t $SERVER_IMAGE:$TARGET \
# -f deploy/docker/Dockerfile.target . > /dev/null 2>&1 && echo "Successfully tagged $SERVER_IMAGE:$TARGET"
# settings:
# username: keedosn
# # from_secret: docker_username
# password: Lokalne5Oprogramowanie@
# # from_secret: docker_password
# repo: git.ego.freeddns.org/egommerce/catalog-svc
# registry: git.ego.freeddns.org
# dockerfile: Dockerfile.target
# tag: dev
# steps:
# - name: static_check
# image: golang:latest
# commands:
# - go install honnef.co/go/tools/cmd/staticcheck@latest
# - cd src && staticcheck ./...
# volumes:
# - name: gopath
# path: /go
# - name: lint
# image: golang:latest
# commands:
# - go install golang.org/x/lint/golint@latest
# - golint ./src/...
# volumes:
# - name: gopath
# path: /go
# - name: analyze
# image: golang:latest
# commands:
# - cd src && go vet ./...
# volumes:
# - name: gopath
# path: /go
# - name: publish_image
# image: plugins/docker
# environment:
# DOCKER_USERNAME:
# from_secret: registry_username
# DOCKER_PASSWORD:
# from_secret: registry_password
# commands:
# - sleep 5
# - ./deploy/image-build.sh
# - ./deploy/image-push.sh
# volumes:
# - name: docker-sock
# path: /var/run
# when:
# branch:
# - main
# services:
# - name: docker
# image: docker:dind
# privileged: true
# volumes:
# - name: docker-sock
# path: /var/run
# - name: etc_hosts
# path: /etc/hosts
# volumes:
# - name: gopath
# temp: {}
# - name: docker-sock
# temp: {}
# - name: etc_hosts
# host:
# path: /etc/hosts

View File

@@ -2,16 +2,16 @@ DEPLOY_DIR := ./deploy
SRC_DIR := ./src
build-image-dev:
- sh ${DEPLOY_DIR}/image-build.sh dev
- sh ${DEPLOY_DIR}/scripts/image-build.sh dev
build-image-prod:
- sh ${DEPLOY_DIR}/image-build.sh
- sh ${DEPLOY_DIR}/scripts/image-build.sh
push-image-dev:
- sh ${DEPLOY_DIR}/image-push.sh dev
- sh ${DEPLOY_DIR}/scripts/image-push.sh dev
push-image-prod:
- sh ${DEPLOY_DIR}/image-push.sh
- sh ${DEPLOY_DIR}/scripts/image-push.sh
build-local-scheduler:
- go build -C ${SRC_DIR} -o ../deploy/scheduler cmd/scheduler/main.go

View File

@@ -0,0 +1,5 @@
FROM docker.io/golang:1.25-alpine AS golang_image
FROM docker.io/alpine:3.22
COPY --from=golang_image /usr/local/go /usr/local/go

View File

@@ -12,7 +12,7 @@ TARGET=${1:-latest}
[ ! -d "src/vendor" ] && sh -c "cd src; go mod vendor"
echo "Building target $IMAGE_PREFIX images..."
docker build --rm -t "$BUILDER_IMAGE" -f Dockerfile.builder .
docker build --rm -t "$BUILDER_IMAGE" -f deploy/docker/Dockerfile.builder .
if [ $TARGET = "latest" ]
then
@@ -24,7 +24,7 @@ then
--build-arg BUILD_TIME \
--rm --cache-from $SERVER_IMAGE:$TARGET \
-t $SERVER_IMAGE:$TARGET \
-f Dockerfile.target . > /dev/null 2>&1 && echo "Successfully tagged $SERVER_IMAGE:$TARGET"
-f deploy/docker/Dockerfile.target . > /dev/null 2>&1 && echo "Successfully tagged $SERVER_IMAGE:$TARGET"
# WORKER - TODO REMOVE IN FUTURE - cause we copy worker binary to the server image
# docker build \
@@ -35,7 +35,7 @@ then
# --build-arg BUILD_TIME \
# --rm --cache-from $WORKER_IMAGE:$TARGET \
# -t $WORKER_IMAGE:$TARGET \
# -f Dockerfile.target . >/dev/null 2>&1 && echo "Successfully tagged $WORKER_IMAGE:$TARGET"
# -f deploy/docker/Dockerfile.target . >/dev/null 2>&1 && echo "Successfully tagged $WORKER_IMAGE:$TARGET"
else
# DEV
docker build \
@@ -44,7 +44,7 @@ else
--build-arg BUILDER_IMAGE=$BUILDER_IMAGE \
--build-arg BUILD_TIME \
--rm --no-cache -t $SERVER_IMAGE:$TARGET \
-f Dockerfile.target . > /dev/null 2>&1 && echo "Successfully tagged $SERVER_IMAGE:$TARGET"
-f deploy/docker/Dockerfile.target . > /dev/null 2>&1 && echo "Successfully tagged $SERVER_IMAGE:$TARGET"
# WORKER
# docker build \
@@ -55,7 +55,7 @@ else
# --build-arg BUILD_TIME \
# --rm --no-cache \
# -t $WORKER_IMAGE:$TARGET \
# -f Dockerfile.target . >/dev/null 2>&1 && echo "Successfully tagged $WORKER_IMAGE:$TARGET"
# -f deploy/docker/Dockerfile.target . >/dev/null 2>&1 && echo "Successfully tagged $WORKER_IMAGE:$TARGET"
fi
echo "Done."

View File

@@ -3,15 +3,22 @@ package app
import (
"context"
"log"
"os"
"time"
redis "github.com/go-redis/redis/v8"
"github.com/jackc/pgx/v5/pgxpool"
db "github.com/jackc/pgx/v5/pgxpool"
amqp "github.com/rabbitmq/amqp091-go"
)
type (
Plugin struct {
name string
connect PluginConnectFn
}
PluginConnectFn func() any // returns connection handle
)
type PluginManager struct {
plugins map[string]any
}
@@ -22,68 +29,144 @@ func NewPluginManager() *PluginManager {
}
}
func (pm *PluginManager) addPlugin(name string, fn PluginFn) {
func (pm *PluginManager) addPlugin(name string, fn PluginConnectFn) {
pm.plugins[name] = fn()
}
func (pm *PluginManager) getCache() *redis.Client {
func (pm *PluginManager) GetCache() *redis.Client {
return (pm.plugins["cache"]).(*redis.Client)
}
func (pm *PluginManager) getDatabase() *pgxpool.Pool {
func (pm *PluginManager) GetDatabase() *pgxpool.Pool {
return (pm.plugins["database"]).(*pgxpool.Pool)
}
func (pm *PluginManager) getEventbus() *amqp.Channel {
func (pm *PluginManager) GetEventbus() *amqp.Channel {
return (pm.plugins["eventbus"]).(*amqp.Channel)
}
func CachePlugin(cnf *Config) Plugin {
// plugin := &Plugin{
// name: "cache",
// connectFn: func() any {},
// afterConnFn: func() any {},
// }
connectFn := func() *redis.Client {
log.Println("establishing api-cache connection...")
return redis.NewClient(&redis.Options{
Addr: cnf.CacheAddr,
Username: cnf.CacheUsername,
Password: cnf.CachePassword,
DB: 0, // TODO
DialTimeout: 100 * time.Millisecond, // TODO
})
}
// checking if the connection is still alive and try to reconnect when it is not
go func(conn *redis.Client) {
tick := time.NewTicker(5 * time.Second) // is 5 seconds is not too much?
defer tick.Stop()
for {
select {
case <-tick.C:
if err := conn.Ping(context.Background()).Err(); err != nil {
log.Println("lost connection with api-cache. Reconnecting...")
conn = connectFn()
}
}
}
}(connectFn())
return Plugin{
name: "cache",
fn: func() any {
return redis.NewClient(&redis.Options{
Addr: cnf.CacheAddr,
Username: cnf.CacheUsername,
Password: cnf.CachePassword,
DB: 0, // TODO
DialTimeout: 100 * time.Millisecond, // TODO
})
connect: func() any {
return connectFn
},
}
}
func DatabasePlugin(cnf *Config) Plugin {
connectFn := func() *pgxpool.Pool {
log.Println("establishing db-postgres connection...")
conn, err := pgxpool.New(context.Background(), cnf.DbURL)
if err != nil {
log.Printf("failed to connect to the database: %s. Err: %s\n", cnf.DbURL, err.Error())
return nil
// os.Exit(1)
}
return conn
}
// checking if the connection is still alive and try to reconnect when it is not
go func(conn *pgxpool.Pool) {
tick := time.NewTicker(5 * time.Second) // is 5 seconds is not too much?
defer tick.Stop()
for {
select {
case <-tick.C:
if err := conn.Ping(context.Background()); err != nil {
log.Println("lost connection with db-postgres. Reconnecting...")
conn = connectFn()
}
}
}
}(connectFn())
return Plugin{
name: "database",
fn: func() any {
dbConn, err := db.New(context.Background(), cnf.DbURL)
if err != nil {
log.Fatalf("Failed to connect to the Database: %s. Err: %v\n", cnf.DbURL, err)
os.Exit(1)
}
return dbConn
connect: func() any {
return connectFn
},
}
}
func EventbusPlugin(cnf *Config) Plugin {
connectFn := func() *amqp.Channel {
log.Println("establishing api-eventbus connection...")
conn, err := amqp.Dial(cnf.EventbusURL)
if err != nil {
log.Fatalf("failed to connect to the eventbus: %s. Err: %v\n", cnf.EventbusURL, err.Error())
return nil
}
chn, err := conn.Channel()
if err != nil {
log.Fatalf("failed to open new eventbus channel. Err: %v\n", err.Error())
return nil
}
return chn
}
// checking if the connection is still alive and try to reconnect when it is not
go func(chn *amqp.Channel) {
tick := time.NewTicker(5 * time.Second) // is 5 seconds is not too much?
defer tick.Stop()
for {
select {
case <-tick.C:
if closed := chn.IsClosed(); closed {
log.Println("lost connection with api-eventbus. Reconnecting...")
chn = connectFn()
}
}
}
}(connectFn())
return Plugin{
name: "eventbus",
fn: func() any {
conn, err := amqp.Dial(cnf.EventbusURL)
if err != nil {
log.Fatalf("Failed to connect to the Eventbus: %s. Err: %v\n", cnf.EventbusURL, err)
os.Exit(1)
}
chn, err := conn.Channel()
if err != nil {
log.Fatalf("Failed to open new Eventbus channel. Err: %v\n", err)
os.Exit(1)
}
return chn
connect: func() any {
return connectFn
},
}
}