Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
wrapper with client is initialized with standard action workflows.
  • Loading branch information
kferrone committed Dec 6, 2023
0 parents commit 9057aaf
Show file tree
Hide file tree
Showing 15 changed files with 407 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.*
!.git
*.sh
build
dist
wiki
*.egg-info
__pycache__
foo*
51 changes: 51 additions & 0 deletions .github/workflows/image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Publish Image

on:
workflow_dispatch:
inputs:
push:
description: Push the image to the registry
required: true
default: false
type: boolean
workflow_call:
inputs:
push:
description: Push the image to the registry
required: false
default: true
type: boolean
outputs:
image:
description: The URI of the image
value: ${{ jobs.build_image.outputs.image }}
secrets:
DOCKER_USERNAME:
description: Docker username
required: true
DOCKER_PASSWORD:
description: Docker password
required: true

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build_image:
name: Image
runs-on: ubuntu-latest
outputs:
image: ${{ steps.build_image.outputs.uri }}
steps:

- name: Checkout code
uses: actions/checkout@v3

- name: Build and Push Docker Image
id: build_image
uses: duplocloud/actions/build-image@main
with:
platforms: linux/amd64 # ,linux/arm64 # makes it take longer
push: ${{ inputs.push }}
docker-username: ${{ secrets.DOCKER_USERNAME }}
docker-password: ${{ secrets.DOCKER_PASSWORD }}
build-args: >
PY_VERSION=3.11
13 changes: 13 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Publish Version

on:
push:
tags:
- '*'

jobs:

image:
name: Publish
uses: ./.github/workflows/image.yml
secrets: inherit
56 changes: 56 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Tests

on:
workflow_dispatch: {}
workflow_call: {}
push: {}

jobs:
test:

runs-on: ubuntu-latest
strategy:
matrix:
# was unable to biuld with: 3.7, 3.8, or 3.9
python-version: ["3.10", "3.11"]

steps:

# checkout code
- name: Checkout Code
uses: actions/checkout@v3

# install python
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

# install the project
- name: Install dependencies
run: |
pip install .[build]
pip install .[test]
pip install .
# do linting
- name: Lint with ruff
run: |
# stop the build if there are Python syntax errors or undefined names
# ruff --format=github --select=E9,F63,F7,F82 --target-version=py37 .
ruff ./src
# run the tests
- name: Test with pytest
run: |
pytest src --junit-xml=test-results.xml
- name: Surface failing tests
if: always()
uses: pmeier/pytest-results-action@main
with:
path: test-results.xml
summary: true
display-options: fEX
fail-on-empty: true
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.direnv
.envrc
build
dist
*.egg-info
.ruff_cache
.pytest_cache
.coverage
__pycache__
.mypy_cache
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changelog

Note: version releases in the 0.x.y range may introduce breaking changes.

## 0.0.1

minor: initial version

34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
ARG PY_VERSION=3.11

# Stage 1: Build the package
FROM python:$PY_VERSION AS builder

# Set the working directory in the container
WORKDIR /app

# Copy the source code, pyproject.toml, .git file to the container
COPY . .

# Install build dependencies
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir .[build]

# Build the package
RUN python -m build --no-isolation

# Stage 2: Install the package in a slimmer container
FROM python:$PY_VERSION-slim

# Set the working directory in the container
WORKDIR /app

# Copy the built package from the previous stage
COPY --from=builder /app/dist ./dist/
COPY --from=builder /app/pipe.yml ./pipe.yml

# Install the package using pip
RUN pip install --no-cache-dir ./dist/*.whl && \
rm -rf ./dist

# Set the entrypoint command for the container
ENTRYPOINT ["duploctl-pipe"]
13 changes: 13 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright @ 2023 DuploCloud

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Bitbucket Pipe for Duploctl

A bitbucket wrapper for the [duploctl](https://github.com/duplocloud/duploctl). Implements the bitbucket pipe tools and the duploctl as python libraries to give a nice and integrated kinda feel to it.

## YAML Definition

```yaml
- pipe: docker://duplocloud/duploctl-pipe:1.0.0
variables:
DUPLO_TOKEN: '<string>'
DUPLO_HOST: '<string>'
DUPLO_TENANT: '<string>'
```
## Variables
| Variable | Usage |
| -------- | ----- |
| DUPLO_TOKEN | Auth token for Duplo |
| DUPLO_HOST | The domain of your Duplo instance |
| DUPLO_TENANT | The tenant where the service is in |
## Prerequisites
To make an update to a service you will need a duplo token.
22 changes: 22 additions & 0 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
variable "TAG" {
default = "0.0.1"
}

variable "REGISTRY" {
default = "duplocloud"
}

group "default" {
targets = ["duploctl-pipe"]
}

target "duploctl-pipe" {
tags = [
"${REGISTRY}/bitbucket-deploy-pipe:latest",
"${REGISTRY}/bitbucket-deploy-pipe:${TAG}"
]
platforms = [
"linux/amd64",
"linux/arm64/v8"
]
}
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
services:

duploctl-pipe:
image: duplocloud/duploctl-pipe:0.0.1
build:
context: .
dockerfile: Dockerfile
tags:
- "duplocloud/bitbucket-deploy-pipe:latest"
x-bake:
platforms:
- linux/amd64
- linux/arm64
- linux/arm64/v8
environment:
DUPLO_HOST: $DUPLO_HOST
DUPLO_TOKEN: $DUPLO_TOKEN
DUPLO_TENANT: $DUPLO_TENANT
22 changes: 22 additions & 0 deletions pipe.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Duploctl Pipe
image: duplocloud/duploctl-pipe:0.0.1
description: Use duploctl as a bitbucket pipe.
category: Deployment
repository: https://github.com/duplocloud/duploctl-pipe
vendor:
name: DuploCloud
website: https://duplocloud.com/
maintainer:
name: DuploCloud
website: https://duplocloud.com/
tags:
- deployment
- images
- duplocloud
variables:
- name: DUPLO_HOST
default: "$DUPLO_HOST"
- name: DUPLO_TOKEN
default: "$DUPLO_TOKEN"
- name: DUPLO_TENANT
default: "$DUPLO_TENANT"
Empty file added pipe/__init__.py
Empty file.
45 changes: 45 additions & 0 deletions pipe/pipe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from bitbucket_pipes_toolkit import Pipe, yaml, get_variable, get_logger
from duplocloud.client import DuploClient

# some global vars
REQUESTS_DEFAULT_TIMEOUT = 10

# Required vars for updating a service
schema = {
'DUPLO_TOKEN': {'required': True, 'type': 'string'},
'DUPLO_HOST': {'required': True, 'type': 'string'},
'DUPLO_TENANT': {'required': True, 'type': 'string'}
}

logger = get_logger()

class DuploctlPipe(Pipe):
"""Duplo Deploy Pipe"""
url = None
headers = None
service = None
image = None
tenant_name = None

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.duploctl = DuploClient(
host=self.get_variable("DUPLO_HOST"),
token=self.get_variable("DUPLO_TOKEN"),
tenant=self.get_variable("DUPLO_TENANT"))

def run(self):
super().run()
svc = self.duploctl.load("tenant")
res = svc.list()
logger.info("Tenant list: %s", res)


def main():
with open('./pipe.yml', 'r') as metadata_file:
metadata = yaml.safe_load(metadata_file.read())
pipe = DuploctlPipe(pipe_metadata=metadata, schema=schema)
pipe.run()

if __name__ == '__main__':
main()
Loading

0 comments on commit 9057aaf

Please sign in to comment.