Skip to content

Commit

Permalink
ready for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
LeKovr committed Apr 6, 2023
1 parent ad9210c commit b6b9546
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env*
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 dopos
Copyright (c) 2023 Alexey Kovrizhkin <lekovr+dopos@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
134 changes: 134 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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"
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
... <edit .env.sample>
mv .env.sample .env
make up
```

## License

The MIT License (MIT), see [LICENSE](LICENSE).

Copyright (c) 2023 Aleksei Kovrizhkin <[email protected]>
40 changes: 40 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b6b9546

Please sign in to comment.