Skip to content

Commit c796745

Browse files
address reviews
Signed-off-by: prashant-gurung899 <prasantgrg777@gmail.com>
1 parent 1a66dea commit c796745

File tree

4 files changed

+115
-34
lines changed

4 files changed

+115
-34
lines changed

oauth.png

60.5 KB
Loading
60.5 KB
Loading
74.1 KB
Loading

src/assets/woodpeckerCI/woodpeckerCI.md

Lines changed: 115 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ authorName: Prashant Gurung
44
authorAvatar: https://avatars.githubusercontent.com/u/53248463?v=4
55
authorLink: https://github.com/prashant-gurung899
66
createdAt: July 3, 2025
7-
tags: CI/CD
7+
tags: CI/CD, Woodpecker, starlark, docker-compose, Traefik, WCCS
88
banner: https://raw.githubusercontent.com/JankariTech/blog/woodpecker-ci-starlark/src/assets/woodpeckerCI/images/cover.png
99
---
1010

1111
## Background
12-
Continuous Integration (CI) tools are vital for automating the testing and deployment of modern software. One such open-source tool is Woodpecker CI, a lightweight CI/CD system. Woodpecker CI is an open-source continuous integration and delivery platform that helps developers automate building, testing, and deploying their code. It is a community-driven fork and successor of the popular Drone CI project, sharing many design principles and compatibility with Drone pipelines. Traditionally, Woodpecker pipelines are written in YAML. But with the rise of programmable pipelines, we now have the flexibility to define our CI configuration using Starlark — a Python-like configuration language.
12+
Continuous Integration tools are essential to build and test modern software automatically and regularly. Woodpecker CI is one such open-source tool, a lightweight CI/CD system. Woodpecker CI is an open-source continuous integration and delivery system that help developers in automating deployment, builds, and testing of code. It's an open-source fork and alternative to the popular Drone CI project with numerous design similarities and Drone pipeline compatibility. Traditionally, Woodpecker pipelines are YAML, but now that programmable pipelines are in vogue, we can finally have the liberty of defining our CI configuration through Starlark — a Python-ish config language.
1313

14-
In this blog, I’ll walk you through setting up Woodpecker CI with Traefik as a reverse proxy and integrating it with WCCS (Woodpecker CI Config Service) to convert Starlark configurations into YAML files, enabling us to write pipelines in .woodpecker.star files. Here's a high-level view of what we'll cover:
14+
In this article, I will walk you through setting up Woodpecker CI with Traefik as a reverse proxy and [WCCS](https://github.com/opencloud-eu/woodpecker-ci-config-service/) (Woodpecker CI Config Service) to convert Starlark configurations into YAML files so that we can write pipelines in `.star` files. Here is a high-level overview of what we are going through:
1515

1616
- Spinning up a Woodpecker server with Traefik
1717

@@ -24,12 +24,14 @@ In this blog, I’ll walk you through setting up Woodpecker CI with Traefik as a
2424
By the end, you’ll be able to write CI pipelines in Starlark and dynamically convert them to YAML during runtime.
2525

2626
## Prepare Woodpecker secrets via .env
27+
Create a `.env` file to store your environment variables.
28+
2729
```console
2830
#Your woodpecker host
2931
WOODPECKER_HOST=https://<your-ci-server>
3032

3133

32-
# GitHub OAuth Secrets
34+
# GitHub OAuth app Secrets - We'll create OAuth app later
3335
WOODPECKER_GITHUB_CLIENT=XXXXXXXXXXXXXXXX
3436
WOODPECKER_GITHUB_SECRET=XXXXXXXXXXXXXXXXXXXXXXXX
3537

@@ -38,12 +40,52 @@ WOODPECKER_GITHUB_SECRET=XXXXXXXXXXXXXXXXXXXXXXXX
3840
WOODPECKER_AGENT_SECRET=<generated-secret>
3941

4042

41-
# Let’s Encrypt contact email (Traefik will use this)
43+
# letsEncrypt contact email (Traefik will use this)
4244
ACME_EMAIL=admin@example.com
4345
```
4446

45-
## Traefik Configuration
46-
Traefik plays a crucial role in this architecture by handling all the networking complexities - SSL termination, routing, and load balancing
47+
## Setting Up Woodpecker Server and Agent
48+
Let's set up the Woodpecker server and agent services in the `docker-compose.yml` file as show below:
49+
50+
```yml
51+
woodpecker-server:
52+
image: woodpeckerci/woodpecker-server:v3
53+
environment:
54+
- WOODPECKER_LOG_LEVEL=debug
55+
- WOODPECKER_OPEN=false
56+
- WOODPECKER_HOST=${WOODPECKER_HOST}
57+
- WOODPECKER_GITHUB=true
58+
- WOODPECKER_GITHUB_CLIENT=${WOODPECKER_GITHUB_CLIENT}
59+
- WOODPECKER_GITHUB_SECRET=${WOODPECKER_GITHUB_SECRET}
60+
- WOODPECKER_AGENT_SECRET=${WOODPECKER_AGENT_SECRET}
61+
- WOODPECKER_ADMIN=prashant-gurung899
62+
# The following variable is where we set our Woodpecker CI Config Service (Starlark Conversion Service) later
63+
- WOODPECKER_CONFIG_SERVICE_ENDPOINT=http://<your-config-service-server>
64+
volumes:
65+
- woodpecker-server-data:/var/lib/woodpecker/
66+
networks:
67+
- woodpecker-net
68+
69+
woodpecker-agent:
70+
image: woodpeckerci/woodpecker-agent:v3
71+
restart: always
72+
depends_on:
73+
- woodpecker-server
74+
volumes:
75+
- woodpecker-agent-config:/etc/woodpecker
76+
- /var/run/docker.sock:/var/run/docker.sock
77+
environment:
78+
- WOODPECKER_LOG_LEVEL=debug
79+
- WOODPECKER_SERVER=woodpecker-server:9000
80+
- WOODPECKER_AGENT_SECRET=${WOODPECKER_AGENT_SECRET}
81+
networks:
82+
- woodpecker-net
83+
```
84+
85+
## Traefik Configuration for HTTPS
86+
So far our woodpecker server runs on HTTP so to serve it on HTTPS we need to configure Traefik.
87+
Traefik plays a crucial role in this architecture by handling all the networking complexities - SSL termination, routing, and load balancing.
88+
Add the following Traefik service in the same `docker-compose.yml` file:
4789

4890
```yml
4991
version: "3.9"
@@ -75,12 +117,12 @@ services:
75117
This configuration:
76118

77119
- Sets up Traefik to listen on ports 80 and 443
78-
- Configures Let's Encrypt for automatic SSL certificate management
120+
- Configures automatic SSL certificate management via [letsEncrypt](https://letsencrypt.org/)
79121
- Enables Docker provider to automatically detect new services
80122
- Mounts necessary volumes for certificate storage and Docker socket access
81123

82-
## Setting Up Woodpecker Server and Agent
83-
Now that we have Traefik running, let's set up the Woodpecker server and agent services. Here's the essential setup:
124+
<!-- ## Setting Up Woodpecker Server and Agent
125+
Now that we have Traefik running, let's set up the Woodpecker server and agent services in the same `docker-compose.yml` file:
84126

85127
```yml
86128
woodpecker-server:
@@ -129,15 +171,19 @@ Now that we have Traefik running, let's set up the Woodpecker server and agent s
129171
- WOODPECKER_AGENT_SECRET=${WOODPECKER_AGENT_SECRET}
130172
networks:
131173
- woodpecker-net
132-
```
174+
``` -->
133175

134176
## Authenticating with GitHub
135177

178+
Woodpecker cannot do anything by itself, it needs a forge (the service where the repositories are hosted). Woodpecker supports [various forges](https://woodpecker-ci.org/docs/administration/configuration/forges/overview), for this blog we will focus on GitHub.
179+
136180
To connect GitHub with Woodpecker:
137181

138-
1. Register a new OAuth application in your GitHub developer settings.
182+
1. Register a new OAuth application in your GitHub developer [settings](https://github.com/settings/applications/new).
183+
184+
2. In your GitHub OAuth App, set the authorization callback URL to `https://<your-ci-server>/authorize`
139185

140-
2. Set the callback URL to `https://<your-ci-server>/authorize`
186+
![Callback URL](https://raw.githubusercontent.com/JankariTech/blog/woodpecker-ci-starlark/src/assets/woodpeckerCI/images/oauth.png)
141187

142188
3. Copy the generated Client ID and Secret.
143189

@@ -148,47 +194,59 @@ After that, you can log into the Woodpecker web UI using your GitHub account.
148194
![GitHub Login](https://raw.githubusercontent.com/JankariTech/blog/woodpecker-ci-starlark/src/assets/woodpeckerCI/images/github.png)
149195

150196
## Enabling a Repository
197+
Before enabling a repo in the Woodpecker CI server, make sure to have a GitHub repository ready. You can use an existing repo of your own or create a new empty one. We will be making a pull request to the repo to trigger CI later.
198+
151199
From the Woodpecker UI:
152200

153201
- Click on Add Repository.
154202

155203
![Add Repo](https://raw.githubusercontent.com/JankariTech/blog/woodpecker-ci-starlark/src/assets/woodpeckerCI/images/add.png)
156204

157-
- Enable it.
205+
- Enable it. For this blog, I am using an existing repo called `Drum-KIT` which has already been enabled(as you can see in the last row of the image below).
158206

159207
![Enable Repo](https://raw.githubusercontent.com/JankariTech/blog/woodpecker-ci-starlark/src/assets/woodpeckerCI/images/enable.png)
160208

161209
Woodpecker will automatically add the necessary webhooks to the repo.
162210

211+
## Triggering Your First CI Run
212+
While we are trying to integrate a starlark conversion service, woodpecker CI supports the default `.yml` pipelines.
213+
So. now we can trigger our first CI using a traditional YAML configuration as show below.
214+
Create a new branch <your-branch-name> and add the following configuration in the root of your enabled github repo with name `.woodpecker.yml`.
215+
216+
217+
```yaml
218+
steps:
219+
- name: hello
220+
image: alpine
221+
commands:
222+
- echo "Hello from CI"
223+
- echo "--------------------"
224+
- echo "This is my first CI BUILD"
225+
- echo "--------------------"
226+
when:
227+
event: pull_request
228+
branch: master
229+
```
163230

164-
After enabling your desired repository, there's one more thing that you need to do i.e. to set pipeline config path.
165-
166-
- From the settings of your Woodpecker Server, go to repositories and click on the enabled repo's settings icon as shown below:
167-
168-
![Settings](https://raw.githubusercontent.com/JankariTech/blog/woodpecker-ci-starlark/src/assets/woodpeckerCI/images/settings.png)
169-
170-
- Then, add `.woodpecker.star` as pipeline config path and save it:
231+
Now that you have your `.woodpecker.yaml` file ready, you can commit and push it to your enabled GitHub repository and then, open a Pull Request from your branch <your-branch-name> to master/main according to you repo.
232+
Once the PR is created, Woodpecker will automatically fetch the pipeline configuration, and start your first CI run. You can then head over to the Woodpecker UI to watch the build logs in real time.
171233

172-
![Pipeline Config](https://raw.githubusercontent.com/JankariTech/blog/woodpecker-ci-starlark/src/assets/woodpeckerCI/images/path.png)
234+
![Yaml Pipleine](https://raw.githubusercontent.com/JankariTech/blog/woodpecker-ci-starlark/src/assets/woodpeckerCI/images/yaml.png)
173235

174-
## Generating the Public Key
175-
Every request sent by Woodpecker is signed using a http-signature by a private key (ed25519) generated on the first start of the Woodpecker server. You can get the public key for the verification of the http-signature from:
176-
```console
177-
http(s)://your-ci-server/api/signature/public-key
178-
```
179-
Store that public key into `keys/public.pem` in the same directory level as your docker compose, it will be needed for signature verification.
236+
Now that we have already set up the woodpecker server and triggered pipelines using the traditional `.yaml` configuration, let's now integrate WCCS to unlock flexibility and define our pipelines in Starlark.
180237

181238
## Setting Up WCCS-Woodpecker CI Config Service (Starlark Conversion Service)
182239
The Woodpecker Config Conversion Service (WCCS) is a lightweight web service created and maintained by [Opencloud-eu](https://opencloud.eu/en). It enables Woodpecker CI to convert pipeline definitions written in Starlark into standard YAML on the fly by receiving a signed POST request from Woodpecker.
183240
You can easily deploy WCCS using their official Docker image available on Docker Hub: [opencloudeu/wccs](https://hub.docker.com/r/opencloudeu/wccs).
241+
Update your `docker-compose.yml` to include the WCCS service:
184242
```yml
185243
wccs:
186244
image: opencloudeu/wccs:latest
187245
container_name: wccs
188246
command: server
189247
environment:
190248
- WCCS_LOG_LEVEL=debug
191-
- WCCS_SERVER_PUBLIC_KEY=/keys/public.pem
249+
- WCCS_SERVER_PUBLIC_KEY=/keys/public.pem #path to public key(generated in the section below)
192250
volumes:
193251
- /opt/woodpecker/keys:/keys
194252
- /etc/ssl/certs:/etc/ssl/certs:ro
@@ -210,15 +268,38 @@ networks:
210268
driver: bridge
211269
```
212270

271+
## Generating the Public Key
272+
Before running any pipeline, woodpecker server sends a POST request to an external config service (in our case WCCS) with all current config file and build information of the current repository. The external service takes the information and sends back the pipeline configurations. In our case, this is how a starlark file is being converted into yaml configurations.
273+
274+
And before WCCS can accept and process those requests, it needs to verify that the requests are trusted and coming from the woodpecker server.
275+
276+
Every request sent by Woodpecker is signed using a http-signature by a private key (ed25519) generated on the first start of the Woodpecker server. You can get the public key for the verification of the http-signature from:
277+
```console
278+
https://<your-ci-server>/api/signature/public-key
279+
```
280+
Store that public key into `keys/public.pem` in the same directory level as your docker compose. The `public.pem` file is then mounted to the WCCS container as shown in the snippet above and used in env variable `WCCS_SERVER_PUBLIC_KEY`
281+
213282
## Connecting WCCS with Woodpecker
214283
To allow Woodpecker to fetch pipeline configs from WCCS, we added this to the server env:
215284
```console
216285
WOODPECKER_CONFIG_SERVICE_ENDPOINT=http://wccs:8080/ciconfig
217286
```
218-
Woodpecker now sends a signed JSON payload to WCCS whenever a build is triggered. WCCS verifies the signature using the public key and responds with a YAML pipeline based on your .woodpecker.star file.
287+
Woodpecker now sends a signed JSON payload to WCCS whenever a build is triggered. WCCS verifies the signature using the public key and responds with a YAML pipeline based on your `.woodpecker.star` file.
288+
289+
After conneting WCCS with the woodpecker server, there's one more thing that you need to do i.e. to set pipeline config path, because by default Woodpecker will take `.woodpecker.yaml` as it's pipeline configuration.
290+
291+
- From the settings of your Woodpecker server, go to `Repositories` and click on the enabled repo's settings icon as shown below:
292+
293+
![Settings](https://raw.githubusercontent.com/JankariTech/blog/woodpecker-ci-starlark/src/assets/woodpeckerCI/images/settings.png)
294+
295+
- Then, add `.woodpecker.star` as pipeline config path and save it:
296+
297+
![Pipeline Config](https://raw.githubusercontent.com/JankariTech/blog/woodpecker-ci-starlark/src/assets/woodpeckerCI/images/path.png)
219298

220299
## Add a Simple Starlark Pipeline
221-
Here's a simple `.woodpecker.star` example that you can add in your project's root and you're all set:
300+
Here's a simple starlark pipeline configuration example that you can add in your project.
301+
Create a new branch by checking out from your master/main branch.
302+
Add the following configration in the `.woodpecker.star` file in your repo's root
222303
```console
223304
def main(ctx):
224305
return [{
@@ -239,9 +320,9 @@ def main(ctx):
239320
}]
240321
```
241322

242-
## Triggering Your First CI Run
243-
Now that you have your `.woodpecker.star` file ready, commit and push it to your GitHub repository and then, open a Pull Request from your branch <your-branch-name> to master.
244-
Once the PR is created, Woodpecker will automatically send the build request to WCCS, fetch the pipeline config, and start your first CI run. You can head over to the Woodpecker UI to watch the build logs in real time.
323+
## Triggering CI with starlark-powered pipeline
324+
Now that you have your `.woodpecker.star` file ready, commit and push it to your GitHub repository and then, open a new Pull Request from your branch <your-branch-name> to master/main.
325+
Once the PR is created, Woodpecker will automatically send a build request to WCCS, fetch the pipeline configuration, and start your first CI run. You can then head over to the Woodpecker UI to watch the build logs in real time.
245326

246327
![Converted Yaml](https://raw.githubusercontent.com/JankariTech/blog/woodpecker-ci-starlark/src/assets/woodpeckerCI/images/converted.png)
247328

0 commit comments

Comments
 (0)