Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add gitlab provider #22

Closed
wants to merge 61 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
56346e1
fix: gitlab get scopes added
omri2001 Jun 12, 2024
0e4b733
fix: finished newgitlabClient
omri2001 Jun 12, 2024
a01a407
fix: ListFiles complete
omri2001 Jun 12, 2024
c53f18b
fix: get File and getFiles
omri2001 Jun 12, 2024
058756e
fix: SetStatus + PinkHook
omri2001 Jun 12, 2024
05bec39
fix: set and del webhook done
omri2001 Jun 14, 2024
a3e6600
fix: small change setWebhook
omri2001 Jun 14, 2024
5dcb125
fix: done handlePaylod
omri2001 Jun 18, 2024
fbd0096
fix: pr review changes and fixed scopes
omri2001 Jun 19, 2024
97207c8
fix: first test done
omri2001 Jun 27, 2024
04c9619
fix: some pr changes resolving
omri2001 Jun 27, 2024
748a633
docs: added provider and url to chart
omri2001 Jun 29, 2024
e7908e2
fix: done utils tests
omri2001 Jun 29, 2024
446bb17
fix: started gitlab tests
omri2001 Jun 29, 2024
eeaa407
fix: added some more tests and fixing bugs
omri2001 Aug 2, 2024
48ad3d7
fix: finished tests now runnning qa
omri2001 Aug 4, 2024
b177656
fix: added some docs
omri2001 Aug 4, 2024
650a79f
fix: added some validations and docs
omri2001 Aug 4, 2024
3ec833a
fix: argo ingress
omri2001 Oct 26, 2024
fbd8249
fix: gitlab init ruby script
omri2001 Nov 10, 2024
453d7dc
ci: add gitlab local support
GoshaDo Nov 10, 2024
6a0fa69
ci: add gitlab local support
GoshaDo Nov 10, 2024
9388bd3
ci: fix e2e service account permissions
GoshaDo Nov 10, 2024
052d92a
fix: gitlab setup script
omri2001 Nov 10, 2024
bb2a407
ci: change rules to working branch
omri2001 Nov 10, 2024
7f2134c
ci: start work on actions
omri2001 Nov 10, 2024
5cdc590
fix: cleaning up
omri2001 Nov 11, 2024
16ad014
fix: context and git provider factory
GoshaDo Nov 10, 2024
7f8b51c
fix: add context
GoshaDo Nov 10, 2024
e04c95b
fix: changes to make it work
omri2001 Nov 11, 2024
e65d39e
ci: add local gitlab at localhost:8080 (#24)
GoshaDo Nov 10, 2024
8fe8df4
fix: changes to make it work
omri2001 Nov 13, 2024
baa6f24
fix: pipe works, small fixes left
omri2001 Nov 16, 2024
3adf727
fix: pipe works, small fixes left
omri2001 Nov 16, 2024
443b950
test: fixed unit tests
omri2001 Nov 21, 2024
faaf16c
test: running e2e
omri2001 Nov 21, 2024
aff7f4a
test: running e2e
omri2001 Nov 21, 2024
03182b4
test: gitlab e2e check
omri2001 Nov 22, 2024
acd6564
fix: gitlab unsetting webhook
omri2001 Nov 22, 2024
02eb9f2
fix: pr changes
omri2001 Nov 23, 2024
0bdabd0
fix: gitlab ruby init script finished
omri2001 Nov 28, 2024
4eb5bac
fix: gitlab init change
omri2001 Nov 30, 2024
76a8b2b
docs: updated docs for gitlab
omri2001 Nov 30, 2024
0ed2975
fix: gitlab script cleanup
omri2001 Dec 1, 2024
987efb9
fix: some space
omri2001 Dec 2, 2024
a01ee2c
ci: changed running branch for testing
omri2001 Dec 2, 2024
13074d2
ci: changed order of jobs in e2e
omri2001 Dec 2, 2024
9afa0ef
ci: e2e to run on branch
omri2001 Dec 2, 2024
29fb625
test: gitlab e2e test
omri2001 Dec 4, 2024
2d7b38f
test: gitlab e2e test
omri2001 Dec 4, 2024
d266bf0
test: gitlab e2e test
omri2001 Dec 4, 2024
b29bdef
test: gitlab e2e test
omri2001 Dec 4, 2024
efa172e
test: gitlab e2e test
omri2001 Dec 4, 2024
62ac8f5
test: fix gitlab test
omri2001 Dec 5, 2024
8eeca89
fix: gitlab rails script
omri2001 Dec 6, 2024
f3d6896
ci: e2e test revert to main
omri2001 Dec 6, 2024
641fff4
ci: e2e check on main
omri2001 Dec 6, 2024
447c263
ci: parallel e2e jobs
omri2001 Dec 24, 2024
4e31509
fix: gitlab e2e
omri2001 Dec 24, 2024
a629573
fix: e2e tests
omri2001 Dec 24, 2024
6507792
docs: align with main
GoshaDo Dec 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 131 additions & 14 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ on:
branches:
- "main"
paths:
- '**'
- '!docs/**'
- "**"
- "!docs/**"
pull_request:
branches:
- "main"
pull_request_target:
branches:
- "main"

concurrency:
group: ${{ github.workflow }} # Bottleneck in ngrok tunnel, only one tunnel can exist for specific token -${{ github.ref }}
Expand All @@ -19,8 +22,123 @@ permissions:
contents: read

jobs:
e2e-env-init:
name: E2E Tests (on development)
gitlab-e2e-env:
name: Gitlab E2E Tests (on development)
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v3
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
- uses: actions/setup-go@v4
with:
go-version: "1.20"
cache: true
- name: Install kind
run: |
curl -sSLo kind "https://github.com/kubernetes-sigs/kind/releases/download/v0.19.0/kind-linux-amd64"
chmod +x kind
sudo mv kind /usr/local/bin/kind
kind version
- name: Install Kubectl
run: |
curl -sSLO "https://storage.googleapis.com/kubernetes-release/release/v1.26.1/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/kubectl
kubectl version --client --output=yaml
- name: Kubernetes KinD Cluster
run: |
make init-kind
- name: install workflows
run: |
make init-argo-workflows
- name: install gitlab
run: |
tokens=$(make init-gitlab ${{ secrets.GITLAB_LICENSE }} | tail -n1)
GROUP_TOKEN=$(echo "$tokens" | grep -oP "(?<=GROUP_TOKEN )\S+")
echo "GITLAB_TOKEN=$GROUP_TOKEN" >> $GITHUB_ENV
- name: Build Docker Image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: localhost:5001/piper:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Check tunnel existence
run: |
echo "NGROK_URL=$(cat ~/ngrok.log | grep -o 'url=https://.*' | cut -d '=' -f 2)" >> $GITHUB_ENV
cat ~/ngrok.log | grep -o 'url=https://.*' | cut -d '=' -f 2
- name: init piper
run: |
helm upgrade --install piper ./helm-chart \
-f ./examples/template.values.dev.yaml \
--set piper.gitProvider.name="gitlab" \
--set piper.gitProvider.token="${{ env.GITLAB_TOKEN }}" \
--set piper.gitProvider.url="http://gitlab-webservice-default.gitlab:8080" \
--set piper.gitProvider.webhook.url="http://piper.default/webhook" \
--set piper.gitProvider.webhook.repoList="piper-e2e-test" \
--set piper.gitProvider.organization.name="pied-pipers" \
--set image.repository=localhost:5001 \
--set piper.argoWorkflows.server.address="${{ env.NGROK_URL }}/argo" \
--set-string env\[0\].name=GIT_WEBHOOK_AUTO_CLEANUP,env\[0\].value="true" && \
sleep 20 && kubectl logs deployment/piper
kubectl wait \
--for=condition=ready pod \
--selector=app=piper \
--timeout=60s
- uses: actions/checkout@v3
with:
repository: "quickube/piper-e2e-test"
path: piper-e2e-test
ref: "main"
- name: inject some changes to piper-e2e-test repo
run: |
mkdir ./gitlab
cd ./gitlab
git clone http://oauth2:${{ env.GITLAB_TOKEN }}@localhost:8080/pied-pipers/piper-e2e-test.git
cp -r ../piper-e2e-test/.workflows ./piper-e2e-test/
cd ./piper-e2e-test
git config user.name 'piper-user'
git config user.email 'piper@example.com'
git add -A
git commit -m "add stuff"
git push
git checkout -b ${{ github.ref_name }}-test
rm ./.workflows/triggers.yaml
cat <<EOF > ./.workflows/triggers.yaml
- events:
- merge_request
- merge_request.open
branches: ["*"]
onStart: ["main.yaml"]
onExit: ["exit.yaml"]
templates: ["templates.yaml"]
EOF
git add -A
git commit -m "${{ github.ref_name }}-test"
git push --set-upstream origin ${{ github.ref_name }}-test -o merge_request.create
- name: Wait for workflow creation
run: |
sleep 10
- name: Check Result
run: |
kubectl logs deployment/piper
kubectl get workflows.argoproj.io -n workflows
BRANCH_VALID_STRING=$(echo ${{ github.ref_name }}-test | tr '[:upper:]' '[:lower:]' | tr '_' '-' | tr -cd 'a-z0-9.\-')

## check if created
RESULT=$(kubectl get workflows.argoproj.io -n workflows --selector=branch=$BRANCH_VALID_STRING --no-headers | grep piper-e2e-test)
[ ! -z "$RESULT" ] && echo "CRD created $RESULT" || { echo "Workflow not exists, existing..."; exit 1; }

## check if status phase not Failed, if yes, show message
RESULT=$(kubectl get workflows.argoproj.io -n workflows --selector=branch=$BRANCH_VALID_STRING --no-headers -o custom-columns="Status:status.phase")
MESSAGE=$(kubectl get workflows.argoproj.io -n workflows --selector=branch=$BRANCH_VALID_STRING --no-headers -o custom-columns="Status:status.message")
[ ! "$RESULT" == "Failed" ] && echo "CRD created $MESSAGE" || { echo "Workflow Failed $MESSAGE, existing..."; exit 1; }
github-e2e-env:
name: Github E2E Tests (on development)
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
Expand Down Expand Up @@ -48,7 +166,7 @@ jobs:
chmod +x kind
sudo mv kind /usr/local/bin/kind
kind version
- name: Install Kubectl
- name: Install Kubectl
run: |
curl -sSLO "https://storage.googleapis.com/kubernetes-release/release/v1.26.1/bin/linux/amd64/kubectl"
chmod +x kubectl
Expand Down Expand Up @@ -79,24 +197,24 @@ jobs:
run: |
helm upgrade --install piper ./helm-chart \
-f ./examples/template.values.dev.yaml \
--set piper.gitProvider.name="github" \
--set piper.gitProvider.token="${{ secrets.GIT_TOKEN }}" \
--set piper.gitProvider.webhook.url="${{ env.NGROK_URL }}/piper/webhook" \
omri2001 marked this conversation as resolved.
Show resolved Hide resolved
--set piper.gitProvider.webhook.repoList={piper-e2e-test} \
--set piper.gitProvider.organization.name="quickube" \
--set image.repository=localhost:5001 \
--set piper.argoWorkflows.server.address="${{ env.NGROK_URL }}/argo" \
--set-string env\[0\].name=GIT_WEBHOOK_AUTO_CLEANUP,env\[0\].value="true" \
--set-string rookout.token="${{ secrets.ROOKOUT_TOKEN }}" && \
--set-string env\[0\].name=GIT_WEBHOOK_AUTO_CLEANUP,env\[0\].value="true" && \
sleep 20 && kubectl logs deployment/piper
kubectl wait \
kubectl wait \
--for=condition=ready pod \
--selector=app=piper \
--timeout=60s
- uses: actions/checkout@v3
with:
repository: 'quickube/piper-e2e-test'
repository: "quickube/piper-e2e-test"
path: piper-e2e-test
ref: 'main'
ref: "main"
- name: inject some changes to piper-e2e-test repo
run: |
cd ./piper-e2e-test
Expand All @@ -116,26 +234,25 @@ jobs:
- name: Wait for workflow creation
run: |
sleep 10

- name: Close Pull Request
uses: peter-evans/close-pull@v3
with:
token: ${{ secrets.GIT_TOKEN }}
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
repository: 'quickube/piper-e2e-test'
repository: "quickube/piper-e2e-test"
comment: Auto-closing pull request
delete-branch: true
- name: Check Result
run: |
kubectl logs deployment/piper
kubectl get workflows.argoproj.io -n workflows
BRANCH_VALID_STRING=$(echo ${{ github.ref_name }}-test | tr '[:upper:]' '[:lower:]' | tr '_' '-' | tr -cd 'a-z0-9.\-')

## check if created
RESULT=$(kubectl get workflows.argoproj.io -n workflows --selector=branch=$BRANCH_VALID_STRING --no-headers | grep piper-e2e-test)
[ ! -z "$RESULT" ] && echo "CRD created $RESULT" || { echo "Workflow not exists, existing..."; exit 1; }

## check if status phase not Failed, if yes, show message
RESULT=$(kubectl get workflows.argoproj.io -n workflows --selector=branch=$BRANCH_VALID_STRING --no-headers -o custom-columns="Status:status.phase")
MESSAGE=$(kubectl get workflows.argoproj.io -n workflows --selector=branch=$BRANCH_VALID_STRING --no-headers -o custom-columns="Status:status.message")
[ ! "$RESULT" == "Failed" ] && echo "CRD created $MESSAGE" || { echo "Workflow Failed $MESSAGE, existing..."; exit 1; }
[ ! "$RESULT" == "Failed" ] && echo "CRD created $MESSAGE" || { echo "Workflow Failed $MESSAGE, existing..."; exit 1; }
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ venv.bak/
# mkdocs documentation
/site

#mirrord config
.mirrord/

# mypy
.mypy_cache/
*.iml
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20-alpine3.16 as builder
FROM golang:1.20-alpine3.16 AS builder

WORKDIR /piper

Expand All @@ -25,7 +25,7 @@ RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/go-build go build -gcflags='all=-N -l' -tags=alpine -buildvcs=false -trimpath ./cmd/piper


FROM alpine:3.16 as piper-release
FROM alpine:3.16 AS piper-release

ENV GIN_MODE=release

Expand Down
2 changes: 1 addition & 1 deletion cmd/piper/piper.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ func main() {
defer stop()
event_handler.Start(ctx, stop, cfg, globalClients)
server.Start(ctx, stop, cfg, globalClients)
}
}
9 changes: 6 additions & 3 deletions docs/configuration/environment_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ The helm chart populates them using [values.yaml](https://github.com/quickube/pi

### Git

* GIT_PROVIDER
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review the changes in this file

The git provider that Piper will use, possible variables: GitHub . We plan to support Bitbucket and GitLab, as well.
- GIT_PROVIDER
The git provider that Piper will use, possible variables: GitHub | Gitlab | Bitbucket

* GIT_TOKEN
The git token that will be used to connect to the git provider.

* GIT_ORG_NAME
- GIT_URL
the git url that will be used, only relevant when running gitlab self hosted

- GIT_ORG_NAME
The organization name.

* GIT_ORG_LEVEL_WEBHOOK
Expand Down
2 changes: 2 additions & 0 deletions docs/configuration/health_check.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Health Check

currently not supported for gitlab / bitbucket

The following examples shows a health check being executed every 1 minute as configured in the helm chart under `livenessProbe`, and triggered by `/healthz` endpoint:

```yaml
Expand Down
9 changes: 5 additions & 4 deletions docs/getting_started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ Piper will use git to fetch the `.workflows` folder and receive events using web

To pick which git provider you are using provide `gitProvider.name` configuration in helm chart (Currently we only support GitHub and Bitbucket).

You must also configure your organization (GitHub) or workspace (Bitbucket) name using `gitProvider.organization.name` in the helm chart.
Also configure you organization (Github), workspace (Bitbucket) or group (Gitlab) name using `gitProvider.organization.name` in helm chart.

#### Git Token Permissions

The token should have access for creating webhooks and read repositories content.
For GitHub, configure `admin:org` and `write:org` permissions in Classic Token.
For Bitbucket, configure `Repositories:read`, `Webhooks:read and write` and `Pull requests:read` permissions (for multiple repos use workspace token).
The token should have access for creating webhooks and read repositories content.</br>
<b>For GitHub</b>, configure `admin:org` and `write:org` permissions in Classic Token. </br>
<b>For Bitbucket</b>, configure `Repositories:read`, `Webhooks:read and write` and `Pull requests:read` permissions (for multiple repos use workspace token). </br>
<b>For Gitlab</b>, configure `read_api`, `write_repository` and `api` (for multiple repos use group token with owner role). </br>

#### Token

Expand Down
2 changes: 1 addition & 1 deletion examples/template.values.dev.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
piper:
gitProvider:
name: github
name: "" # github/bitbucket/gitlab | env: GIT_PROVIDER
token: "GIT_TOKEN"
organization:
name: "ORG_NAME"
Expand Down
19 changes: 16 additions & 3 deletions gitlab.values.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
gitlab:
toolbox:
enabled: false
enabled: true
extraVolumes: |-
- name: piper-config
configMap:
name: piper-setup
extraVolumeMounts: |-
- mountPath: /tmp/scripts/piper-setup.rb
name: piper-config
subPath: piper-setup.rb
readOnly: true
gitlab-shell:
enabled: false
enabled: true
gitlab-pages:
enabled: false
gitlab-exporter:
enabled: false
kas:
minReplicas: 1
webservice:
enabled: true
minReplicas: 1
ingress:
requireBasePath: false
global:
gitlab:
license:
key: license_key
secret: gitlab-license
hosts:
domain: localhost
https: false
Expand All @@ -38,7 +52,6 @@ prometheus:
certmanager:
installCRDs: false
install: false

nginx-ingress:
controller:
ingressClassResource:
Expand Down
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/ktrysmt/go-bitbucket v0.9.66
github.com/stretchr/testify v1.8.4
github.com/tidwall/gjson v1.16.0
github.com/xanzy/go-gitlab v0.113.0
golang.org/x/net v0.17.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/apimachinery v0.24.3
Expand Down Expand Up @@ -45,6 +46,8 @@ require (
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand All @@ -53,7 +56,7 @@ require (
github.com/kr/pretty v0.3.1 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand All @@ -71,7 +74,7 @@ require (
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/oauth2 v0.11.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
Expand Down
Loading
Loading