From b6b95462030a49891525669345a30d4d99927414 Mon Sep 17 00:00:00 2001 From: Alexey Kovrizhkin Date: Thu, 6 Apr 2023 18:37:08 +0300 Subject: [PATCH] ready for testing --- .gitignore | 1 + LICENSE | 2 +- Makefile | 134 +++++++++++++++++++++++++++++++++++++++++++++ README.md | 50 +++++++++++++++++ docker-compose.yml | 40 ++++++++++++++ 5 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 README.md create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e6905a2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env* \ No newline at end of file diff --git a/LICENSE b/LICENSE index 2770930..5323da4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 dopos +Copyright (c) 2023 Alexey Kovrizhkin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..18e7a7e --- /dev/null +++ b/Makefile @@ -0,0 +1,134 @@ +# app custom Makefile + +# Docker repo & image name without version +IMAGE ?= woodpeckerci/woodpecker-server +# Docker image version +IMAGE_VER ?= latest +# Hostname for external access +APP_SITE ?= ci.dev.lan +# App names (db/user name etc) +APP_NAME ?= woodpecker + +# Enable DB usage: +# * Add DB config part to .env.sample +# * Enable db* targets +# * make db-create inside .drone-default target +USE_DB ?= yes + +# ------------------------------------------------------------------------------ +# app custom config + +ADMIN_USERS ?= jean + +AGENT_SECRET ?= $(shell openssl rand -hex 32; echo) + +# Path to /opt/dcape/var. Used only outside drone +DCAPE_ROOT ?= /opt/dcape/var + +# VCS (Version control systems) (gitea/github) config + +VCS_GITHUB_USED ?= false +VCS_GITEA_USED ?= true + +# VCS URL for auth and repos +VCS_URL ?= http://git.dev.lan + +VCS_CLIENT ?= **VCS APP ID** +VCS_SECRET ?= **VCS APP SECRET** + + +# ------------------------------------------------------------------------------ +# .env template (custom part) +# inserted in .env.sample via 'make config' +define CONFIG_CUSTOM +# ------------------------------------------------------------------------------ +# app custom config, generated by make config +# db:$(USE_DB) user:$(ADD_USER) + +ADMIN_USERS=$(ADMIN_USERS) + +# +# VCS (Version control systems) (gitea/github) config +# + +VCS_GITHUB_USED=$(VCS_GITHUB_USED) +VCS_GITEA_USED=$(VCS_GITEA_USED) + +VCS_URL=$(VCS_URL) +VCS_CLIENT=$(VCS_CLIENT) +VCS_SECRET=$(VCS_SECRET) + +# +# Internals +# + +# HTTP proto (based on USE_TLS) +HTTP_PROTO=$(HTTP_PROTO) + +AGENT_SECRET=$(AGENT_SECRET) + +# Path to /opt/dcape/var. Used only outside drone +DCAPE_ROOT=$(DCAPE_ROOT) + +endef + +# ------------------------------------------------------------------------------ +# Find and include DCAPE/apps/drone/dcape-app/Makefile +DCAPE_COMPOSE ?= dcape-compose +DCAPE_MAKEFILE ?= $(shell docker inspect -f "{{.Config.Labels.dcape_app_makefile}}" $(DCAPE_COMPOSE)) +ifeq ($(shell test -e $(DCAPE_MAKEFILE) && echo -n yes),yes) + include $(DCAPE_MAKEFILE) +else + include /opt/dcape-app/Makefile +endif + +# ----------------------------------------------------------------------------- +## Custom app targets +#: + +.PHONY: user-add token-add feed-add + +HEADER ?= 'Content-Type: application/json; charset=utf-8' +API ?= $(HTTP_PROTO)://$(APP_SITE)/api/v1 +ROLE ?= user + +define USER_ADD_DATA +{ + "username": "$(USER)", + "password": "$(PASS)", + "role": "$(ROLE)" +} +endef + +## Add user +user-add: + @json=`echo "$$USER_ADD_DATA" | curl -gsd @- -u "$(USER_NAME):$(USER_PASS)" -H $(HEADER) $(API)/users` ; \ + echo $$json ; + +define TOKEN_ADD_DATA +{ + "name": "$(TOKEN_NAME)" +} +endef + +## Add token +token-add: + @json=`echo "$$TOKEN_ADD_DATA" | curl -gsd @- -u "$(USER):$(PASS)" -H $(HEADER) $(API)/tokens` ; \ + echo $$json ; + +define FEED_ADD_DATA +{ + "name": "$(FEED_NAME)", + "url": "$(FEED_URL)", + "group": "$(FEED_GROUP)" +} +endef + +## Add feed +feed-add: + @json=`echo "$$FEED_ADD_DATA" | curl -gsd @- -u "$(USER):$(PASS)" -H $(HEADER) $(API)/feeds` ; \ + echo $$json ; + + +# printf "%s" "$$json" ; \ +# printf "%s" "$$json" | jq '.success' | grep "false" > /dev/null || echo "RET" diff --git a/README.md b/README.md new file mode 100644 index 0000000..bfc19d9 --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +# dcape-app-woodpecker + +[![GitHub Release][1]][2] [![GitHub code size in bytes][3]]() [![GitHub license][4]][5] + +[1]: https://img.shields.io/github/release/dopos/dcape-app-woodpecker.svg +[2]: https://github.com/dopos/dcape-app-woodpecker/releases +[3]: https://img.shields.io/github/languages/code-size/dopos/dcape-app-woodpecker.svg +[4]: https://img.shields.io/github/license/dopos/dcape-app-woodpecker.svg +[5]: LICENSE + +[Woodpecker CI](https://woodpecker-ci.org/) application package for [dcape](https://github.com/dopos/dcape). + +## Docker image used + +* [woodpecker-server](https://hub.docker.com/r/woodpeckerci/woodpecker-server) +* [woodpecker-agent](https://hub.docker.com/r/woodpeckerci/woodpecker-agent) + +## Requirements + +* linux 64bit (git, make, sed) +* [docker](http://docker.io) +* [dcape](https://github.com/dopos/dcape) v2 +* Git service ([github](https://github.com), [gitea](https://gitea.io) or [gogs](https://gogs.io)) + +## Install + +### By mouse (deploy with drone) + +* Gitea: Fork or mirror this repo in your Git service +* Drone: Activate repo +* Gitea: "Test delivery", config sample will be saved to enfist +* Enfist: Edit config and remove .sample from name +* Gitea: "Test delivery" again (or Drone: "Restart") - app will be installed and started on webhook host + +### By hands + +```bash +git clone --single-branch --depth 1 https://github.com/dopos/dcape-app-woodpecker.git +cd dcape-app-woodpecker +make config +... +mv .env.sample .env +make up +``` + +## License + +The MIT License (MIT), see [LICENSE](LICENSE). + +Copyright (c) 2023 Aleksei Kovrizhkin diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..fcbc002 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,40 @@ +# custom app config +# overrides DCAPE/apps/drone/dcape-app/docker-compose.yml + +version: '2' + +services: + app: + labels: + - "traefik.http.services.app-${APP_TAG}.loadbalancer.server.port=8000" + volumes: + - ${DCAPE_ROOT}/woodpecker_empty:/var/lib/woodpecker/ + environment: + - WOODPECKER_OPEN=false + - WOODPECKER_HOST=${HTTP_PROTO}://${APP_SITE} + - WOODPECKER_AGENT_SECRET=${AGENT_SECRET} + - WOODPECKER_ADMIN=${ADMIN_USERS} + - WOODPECKER_GITHUB=${VCS_GITHUB_USED} + - WOODPECKER_GITHUB_CLIENT=${VCS_CLIENT} + - WOODPECKER_GITHUB_SECRET=${VCS_SECRET} + - WOODPECKER_GITEA=${VCS_GITEA_USED} + - WOODPECKER_GITEA_URL=${VCS_URL} + - WOODPECKER_GITEA_CLIENT=${VCS_CLIENT} + - WOODPECKER_GITEA_SECRET=${VCS_SECRET} + # TODO: - DRONE_GIT_ALWAYS_AUTH=true + + agent: + image: woodpeckerci/woodpecker-agent:latest + command: agent + restart: always + depends_on: + - app + volumes: + - /var/run/docker.sock:/var/run/docker.sock + environment: + - WOODPECKER_SERVER=app:9000 # GRPC server + - WOODPECKER_AGENT_SECRET=${AGENT_SECRET} + - WOODPECKER_DATABASE_DRIVER=postgres + - WOODPECKER_DATABASE_DATASOURCE=postgres://${PGUSER}:${PGPASSWORD}@db/${PGDATABASE}?sslmode=disable + networks: + - lan