diff --git a/.changes/next-release/minor-20181204085425.json b/.changes/next-release/minor-20181204085425.json new file mode 100644 index 0000000..a08a38a --- /dev/null +++ b/.changes/next-release/minor-20181204085425.json @@ -0,0 +1,4 @@ +{ + "type": "minor", + "description": "Initial release" +} diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..6776dd5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +insert_final_newline = true +charset = utf-8 + +[*.md] +trim_trailing_whitespace = false diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c640eaf --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,38 @@ +name: Push Docker Images + +on: + release: + types: [created] + +jobs: + build: + + runs-on: ubuntu-latest + env: + VERSION: ${{ github.event.release.tag_name }} + steps: + - uses: actions/checkout@v2 + + - name: docker build + run: | + docker build -t terrakube-pipe:latest . + + - name: docker login + env: + DOCKER_USER: ${{secrets.DOCKER_USER}} + DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}} + run: | + docker login -u $DOCKER_USER -p $DOCKER_PASSWORD + + - name: Docker tag Pipe Image + run: docker tag $(docker images terrakube-pipe -q) azbuilder/terrakube-pipe:$VERSION + + - name: Docker tag Pipe Image latest + run: docker tag $(docker images terrakube-pipe -q) azbuilder/terrakube-pipe:latest + + - name: Docker Push Pipe + run: docker push azbuilder/terrakube-pipe:$VERSION + + - name: Docker Push Pipe latest + run: docker push azbuilder/terrakube-pipe:latest + \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..03e30fe --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +docker-compose.yaml +bitbucket-pipelines.yml +RELEASING.md \ No newline at end of file diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..c38fa4e --- /dev/null +++ b/.npmignore @@ -0,0 +1,2 @@ +.idea +*.iml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..12c06f6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM alpine:3.15.0 + +RUN apk add --update --no-cache bash &&\ + apk add --no-cache curl &&\ + apk add --no-cache jq + +COPY pipe / +COPY LICENSE.txt pipe.yml README.md / +RUN wget -P / https://bitbucket.org/bitbucketpipelines/bitbucket-pipes-toolkit-bash/raw/0.4.0/common.sh + +RUN chmod a+x /*.sh + +ENTRYPOINT ["/pipe.sh"] diff --git a/LICENSE b/LICENSE index 261eeb9..9d716ad 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright 2022 Alredo España Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -198,4 +198,4 @@ 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. + limitations under the License. \ No newline at end of file diff --git a/README.md b/README.md index 4cc260c..973cf97 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,110 @@ -# terrakube-pipe-bitbucket -Custom bitbucket pipe that allows to run Terrakube jobs inside Bitbuckets pipelines +# Bitbucket Pipelines Pipe: Terrakube Integration + +This pipe is an example to show how easy is to create pipes for Bitbucket Pipelines. + +## YAML Definition + +Add the following snippet to the script section of your `bitbucket-pipelines.yml` file: + +```yaml +script: + - pipe: azbuilder/terrakube-pipe:1.0.0 + variables: + LOGIN_ENDPOINT: "" #optional Default: https://login.microsoftonline.com + TERRAKUBE_TENANT_ID: "" + TERRAKUBE_APPLICATION_ID: "" + TERRAKUBE_APPLICATION_SECRET: "" + TERRAKUBE_APPLICATION_SCOPE: "" #optional Default: api://Terrakube/.default + TERRAKUBE_ORGANIZATION: "" + TERRAKUBE_WORKSPACE: "" + TERRAKUBE_TEMPLATE: "" + TERRAKUBE_ENDPOINT: "" + DEBUG: "" # Optional Default: false +``` +## Variables + +| Variable | Usage | +| -------------------------------- | -------------------------------------------------- | +| LOGIN_ENDPOINT | Default values: https://login.microsoftonline.com | +| TERRAKUBE_TENANT_ID (*) | Azure AD Application tenant ID | +| TERRAKUBE_APPLICATION_ID (*) | Azure AD Application tenant ID | +| TERRAKUBE_APPLICATION_SECRET (*) | Azure AD Application tenant ID | +| TERRAKUBE_APPLICATION_SCOPE | Default value: api://Terrakube/.default | +| TERRAKUBE_ORGANIZATION (*) | Terrakube organization name | +| TERRAKUBE_WORKSPACE (*) | Terrakube workspace name | +| TERRAKUBE_TEMPLATE (*) | Terrakube template name | +| TERRAKUBE_ENDPOINT (*) | Terrakbue api endpoint | + +_(*) = required variable._ + +## Prerequisites + +## Examples + +Basic example: + +```yaml +script: + - pipe: azbuilder/terrakube-pipe:1.0.0 + variables: + TERRAKUBE_TENANT_ID: "36857254-c824-409f-96f5-d3f2de37b016" + TERRAKUBE_APPLICATION_ID: "36857254-c824-409f-96f5-d3f2de37b016" + TERRAKUBE_APPLICATION_SECRET: "SuperSecret" + TERRAKUBE_ORGANIZATION: "terrakube" + TERRAKUBE_WORKSPACE: "bitbucket" + TERRAKUBE_TEMPLATE: "vulnerability-snyk" + TERRAKUBE_ENDPOINT: "https://terrakube.interal/service" +``` + +Advanced example: + +```yaml +script: + - pipe: azbuilder/terrakube-pipe:1.0.0 + variables: + LOGIN_ENDPOINT: "https://login.microsoftonline.com" + TERRAKUBE_TENANT_ID: "36857254-c824-409f-96f5-d3f2de37b016" + TERRAKUBE_APPLICATION_ID: "36857254-c824-409f-96f5-d3f2de37b016" + TERRAKUBE_APPLICATION_SECRET: "SuperSecret" + TERRAKUBE_APPLICATION_SCOPE: "api://TerrakubeApp/.default" + TERRAKUBE_ORGANIZATION: "terrakube" + TERRAKUBE_WORKSPACE: "bitbucket" + TERRAKUBE_TEMPLATE: "vulnerability-snyk" + TERRAKUBE_ENDPOINT: "https://terrakube.interal/service" + DEBUG: "true" +``` + +## Docker Compose Example + +This can be used to test the bitbucket pipeline in your local machine. + +Build the image: +```bash +docker build -t terrakube-pipe:latest . +``` + +Run the bitbucket pipe locally: +```yaml +version: "3.8" +services: + api-server: + image: terrakube-pipe:latest + container_name: terrakube-pipe + environment: + - TERRAKUBE_TENANT_ID=XXXXX + - TERRAKUBE_APPLICATION_ID=XXXX + - TERRAKUBE_APPLICATION_SECRET=XXXX + - TERRAKUBE_ORGANIZATION=XXX + - TERRAKUBE_WORKSPACE=XXX + - TERRAKUBE_TEMPLATE=XXX + - TERRAKUBE_ENDPOINT=XXX + - TERRAKUBE_APPLICATION_SCOPE=XXX +``` +## Support +If you’d like help with this pipe, or you have an issue or feature request, let us know. + +If you’re reporting an issue, please include: + +- the version of the pipe +- relevant logs and error messages +- steps to reproduce diff --git a/pipe.yml b/pipe.yml new file mode 100644 index 0000000..2180651 --- /dev/null +++ b/pipe.yml @@ -0,0 +1,8 @@ +name: Terrakube pipe +image: azbuilder/terrakube-pipe:0.0.1 +description: This pipe will trigger a Terrakube job. +repository: https://github.com/AzBuilder/terrakube-pipe-bitbucket +maintainer: alespa17@gmail.com +tags: + - terrakube + \ No newline at end of file diff --git a/pipe/pipe.sh b/pipe/pipe.sh new file mode 100644 index 0000000..443174a --- /dev/null +++ b/pipe/pipe.sh @@ -0,0 +1,87 @@ +#!/usr/bin/env bash +# +# This pipe is an example to show how easy is to create pipes for Bitbucket Pipelines. +# + +source "$(dirname "$0")/common.sh" + +generate_job_data() +{ + cat <