Skip to content

Commit

Permalink
Gitlab app poc (#2)
Browse files Browse the repository at this point in the history
Gitlab integration 0.1.0
  • Loading branch information
yairsimantov20 authored Jul 20, 2023
1 parent cb8c5ad commit 2fa1f07
Show file tree
Hide file tree
Showing 37 changed files with 2,806 additions and 31 deletions.
22 changes: 9 additions & 13 deletions .github/workflows/release-integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
workflow_dispatch:

jobs:
build-and-push-image:
release-all:
runs-on: ubuntu-latest
permissions:
packages: write
Expand All @@ -24,7 +24,7 @@ jobs:
run: |
GHCR_TOKEN=$(echo ${{ secrets.GITHUB_TOKEN }} | base64)
files=$(find integrations -name "ocean-spec.yaml")
files=$(find integrations/*/.port -name "spec.yaml")
for file in $files; do
# Get the type from ocean-spec.yaml
type=$(yq eval '.type' "$file")
Expand All @@ -41,7 +41,7 @@ jobs:
echo "Image already exists in $repository: port-ocean-$type:$version"
else
echo "Building and pushing new image: port-ocean-$type:$version"
docker build -t "ghcr.io/port-labs/port-ocean-$type:$version" -t "ghcr.io/port-labs/port-ocean-$type:latest" "$folder"
docker build -t "ghcr.io/port-labs/port-ocean-$type:$version" -t "ghcr.io/port-labs/port-ocean-$type:latest" "$folder/.."
docker push "ghcr.io/port-labs/port-ocean-$type" --all-tags
fi
done
Expand All @@ -51,12 +51,9 @@ jobs:
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Upload specifications to s3
run: |
# Directory to search for ocean-spec.yaml files
directory="integrations"
# Temporary file to store the concatenated YAML content
temp_file="temp.yaml"
Expand All @@ -67,14 +64,13 @@ jobs:
aws_s3_bucket="ocean-registry"
# Find all ocean-spec.yaml files under the specified directory
find "$directory" -type f -name "ocean-spec.yaml" > file_list.txt
find integrations/*/.port -type f -name "spec.yaml" > file_list.txt
# Concatenate the YAML files into a temporary file
while IFS= read -r file; do
cat "$file" >> "$temp_file"
echo "---" >> "$temp_file"
echo "- " >> "$temp_file"
sed 's/^/ /' "$file" >> "$temp_file"
done < file_list.txt
# Convert the concatenated YAML file to JSON using yq (install it first if not already installed)
yq -y . < "$temp_file" > "$output_file"
aws s3 cp "$output_file" "s3://$aws_s3_bucket/$output_file"
yq -j . < "$temp_file" > "$output_file"
aws s3 cp "$output_file" "s3://$aws_s3_bucket/$output_file"
6 changes: 6 additions & 0 deletions integrations/gitlab/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.vscode/
assets/
*.md
.git
.gitignore
.env
148 changes: 148 additions & 0 deletions integrations/gitlab/.port/resources/blueprints.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
[
{
"identifier": "microservice",
"title": "Microservice",
"icon": "Service",
"schema": {
"properties": {
"url": {
"title": "URL",
"format": "url",
"type": "string"
},
"description": {
"title": "Description",
"type": "string"
},
"namespace": {
"title": "Namespace",
"type": "string"
},
"full_path": {
"title": "Full Path",
"type": "string"
}
}
}
},
{
"identifier": "mergeRequest",
"title": "Merge Request",
"icon": "GitVersion",
"schema": {
"properties": {
"creator": {
"title": "Creator",
"type": "string"
},
"status": {
"title": "Status",
"type": "string",
"enum": [
"opened",
"closed",
"merged",
"locked"
],
"enumColors": {
"opened": "yellow",
"closed": "red",
"merged": "green",
"locked": "blue"
}
},
"createdAt": {
"title": "Create At",
"type": "string",
"format": "date-time"
},
"updatedAt": {
"title": "Updated At",
"type": "string",
"format": "date-time"
},
"description": {
"title": "Description",
"type": "string",
"format": "markdown"
},
"link": {
"title": "Link",
"format": "url",
"type": "string"
}
}
},
"relations": {
"microservice": {
"target": "microservice",
"required": true,
"many": false
}
}
},
{
"identifier": "issue",
"title": "Issue",
"icon": "GitLab",
"schema": {
"properties": {
"link": {
"title": "Link",
"type": "string",
"format": "url"
},
"description": {
"title": "Description",
"type": "string",
"format": "markdown"
},
"createdAt": {
"title": "Created At",
"type": "string",
"format": "date-time"
},
"closedAt": {
"title": "Closed At",
"type": "string",
"format": "date-time"
},
"updatedAt": {
"title": "Updated At",
"type": "string",
"format": "date-time"
},
"creator": {
"title": "Creator",
"type": "string"
},
"status": {
"title": "Status",
"type": "string",
"enum": [
"opened",
"closed"
],
"enumColors": {
"opened": "green",
"closed": "purple"
}
},
"labels": {
"title": "Labels",
"type": "array",
"items": {
"type": "string"
}
}
}
},
"relations": {
"microservice": {
"target": "microservice",
"required": true,
"many": false
}
}
}
]
54 changes: 54 additions & 0 deletions integrations/gitlab/.port/resources/port-app-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
resources:
- kind: project
selector:
query: 'true'
port:
entity:
mappings:
identifier: .path_with_namespace | gsub(" "; "")
title: .name
blueprint: '"microservice"'
properties:
url: .web_link
description: .description
namespace: .namespace.name
full_path: .namespace.full_path
- kind: mergeRequest
selector:
query: 'true'
port:
entity:
mappings:
identifier: .id | tostring
title: .title
blueprint: '"mergeRequest"'
properties:
creator: .author.name
status: .state
createdAt: .created_at
updatedAt: .updated_at
description: .description
link: .web_url
relations:
microservice: .references.full
- kind: issues
selector:
query: 'true'
port:
entity:
mappings:
identifier: .id | tostring
title: .title
blueprint: '"issue"'
properties:
creator: .author.name
status: .state
createdAt: .created_at
closedAt: .closed_at
updatedAt: .updated_at
description: .description
link: .web_url
labels: '[.labels[]]'
object: .
relations:
microservice: .references.full
27 changes: 27 additions & 0 deletions integrations/gitlab/.port/spec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: v0.1.0
type: gitlab
description: Gitlab integration for Port Ocean
icon: GitLab
features:
- type: gitops
section: GitOps
- type: exporter
section: Git Providers
resources:
- kind: projects
configurations:
- name: tokenMapping
required: true
type: object
description: "Mapping of Gitlab tokens to Port Ocean tokens. example: {\"THE_GROUP_TOKEN\":[\"getport-labs/**\", \"GROUP/PROJECT PATTERN TO RUN FOR\"]}"
sensitive: true
- name: appHost
required: true
type: url
description: The host of the Port Ocean app. Used for setting up the webhooks against the Gitlab.
- name: gitlabHost
required: false
type: url
default: https://gitlab.com
description: The host of the Gitlab instance. If not specified, the default will be https://gitlab.com.
ingressRequired: true
16 changes: 16 additions & 0 deletions integrations/gitlab/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM python:3.11-slim-buster

ENV LIBRDKAFKA_VERSION 1.9.2

WORKDIR /app

RUN apt update && apt install -y wget make g++ libssl-dev autoconf automake libtool curl
RUN wget https://github.com/edenhill/librdkafka/archive/v${LIBRDKAFKA_VERSION}.tar.gz && \
tar xvzf v${LIBRDKAFKA_VERSION}.tar.gz && \
(cd librdkafka-${LIBRDKAFKA_VERSION}/ && ./configure && make && make install && ldconfig)

COPY . /app

RUN make install

ENTRYPOINT make run
71 changes: 71 additions & 0 deletions integrations/gitlab/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
ACTIVATE := . .venv/bin/activate

define run_checks
exit_code=0; \
cd $1; \
poetry check || exit_code=$$?;\
poetry lock --check || exit_code=$$?;\
mypy . || exit_code=$$?; \
ruff . || exit_code=$$?; \
black --check . || exit_code=$$?; \
if [ $$exit_code -eq 1 ]; then \
echo "\033[0;31mOne or more checks failed with exit code $$exit_code\033[0m"; \
else \
echo "\033[0;32mAll checks executed successfully.\033[0m"; \
fi; \
exit $$exit_code
endef

define install_poetry
if ! command -v poetry &> /dev/null; then \
pip install --upgrade pip; \
pip install poetry; \
else \
echo "Poetry is already installed."; \
fi
endef

define deactivate_virtualenv
if [ -n "$$VIRTUAL_ENV" ]; then \
unset VIRTUAL_ENV; \
unset PYTHONHOME; \
unset -f pydoc >/dev/null 2>&1; \
OLD_PATH="$$PATH"; \
PATH=$$(echo -n "$$PATH" | awk -v RS=: -v ORS=: '/\/virtualenv\/bin$$/ {next} {print}'); \
export PATH; \
hash -r; \
echo "Deactivated the virtual environment."; \
fi
endef

.SILENT: install lint run test clean

install:
$(call deactivate_virtualenv) && \
$(call install_poetry) && \
poetry install --with dev

lint:
$(ACTIVATE) && \
$(call run_checks,.)

run:
$(ACTIVATE) && ocean sail

test: lint
$(ACTIVATE) && poetry run pytest

clean:
@find . -name '.venv' -type d -exec rm -rf {} \;
@find . -name '*.pyc' -exec rm -rf {} \;
@find . -name '__pycache__' -exec rm -rf {} \;
@find . -name 'Thumbs.db' -exec rm -rf {} \;
@find . -name '*~' -exec rm -rf {} \;
rm -rf .cache
rm -rf build
rm -rf dist
rm -rf *.egg-info
rm -rf htmlcov
rm -rf .tox/
rm -rf docs/_build
rm -rf dist/
Loading

0 comments on commit 2fa1f07

Please sign in to comment.