-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wrapper with client is initialized with standard action workflows.
- Loading branch information
0 parents
commit 9057aaf
Showing
15 changed files
with
407 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.* | ||
!.git | ||
*.sh | ||
build | ||
dist | ||
wiki | ||
*.egg-info | ||
__pycache__ | ||
foo* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.