From 501d173e6fa47c438aad4abd26a2a4187fbe35ce Mon Sep 17 00:00:00 2001 From: Matthew B White Date: Fri, 3 Feb 2023 11:37:55 +0000 Subject: [PATCH] New code Signed-off-by: Matthew B White --- .github/playbooks/000-hello.yaml | 7 ++++++ .github/workflows/test.yml | 31 +++++++++++++++++++++++++ Dockerfile | 7 ++++++ README.md | 39 ++++++++++++++++++++++++++++++-- action.yaml | 20 ++++++++++++++++ entrypoint.sh | 28 +++++++++++++++++++++++ 6 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 .github/playbooks/000-hello.yaml create mode 100644 .github/workflows/test.yml create mode 100644 Dockerfile create mode 100644 action.yaml create mode 100755 entrypoint.sh diff --git a/.github/playbooks/000-hello.yaml b/.github/playbooks/000-hello.yaml new file mode 100644 index 0000000..7242935 --- /dev/null +++ b/.github/playbooks/000-hello.yaml @@ -0,0 +1,7 @@ +--- +- hosts: localhost + tasks: + - ansible.builtin.debug: + msg: "Hello" + + \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..a8f55f1 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,31 @@ +name: Tests + +on: + push: + branches: + - main + pull_request: + +defaults: + run: + shell: bash + +jobs: + test: + name: Test + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest] + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Run Playbook + uses: ./ + with: + playbook: .github/playbooks/000-hello.yaml + + + + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1774a4d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,7 @@ +FROM ghcr.io/ibm-blockchain/fabric-ansible:2.0.0-beta +USER root +RUN curl -sSL https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 -o /usr/local/bin/jq \ + && chmod +x /usr/local/bin/jq + +COPY entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md index 0a7e91e..10ce330 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,37 @@ -# fabric-ansible-action -GitHub Action to run Ansible Playbooks for Hyperledger Fabric +# :gear: `fabric-ansible-action` +> Action to setup Hyperledger Fabric CLIs + +## About + +This action will run an Ansible Playbook using the ["Ansible Collection For Fabric"](https://github.com/IBM-Blockchain/ansible-collection) +It is based off the [v2.0.0-beta docker image](https://github.com/IBM-Blockchain/ansible-collection/pkgs/container/fabric-ansible). +## Usage + +To run a playbook + +```yaml + - name: Create the Fabric Operations Console + uses: hyperledgendary/fabric-ansible-action + with: + playbook: playbooks/operator_console_playbooks/02-console-install.yml +``` + +To run a playbook with an additional Ansible Arugments file + +```yaml + - name: Create the Fabric Operations Console + uses: hyperledgendary/fabric-ansible-action + with: + playbook: playbooks/operator_console_playbooks/02-console-install.yml + argsfile: _cfg/domain.yml +``` + +## Inputs +The actions supports the following inputs: + +- `playbook`: Path to the playbook to run +- `argsfile`: path to an additional args file to supply to Ansible (standard Ansible yaml format) + + +## License +[APACAHE-2.0](LICENSE). diff --git a/action.yaml b/action.yaml new file mode 100644 index 0000000..180c627 --- /dev/null +++ b/action.yaml @@ -0,0 +1,20 @@ +# action.yml +name: 'Fabric Ansible Action' +description: 'Fabric Ansible Action' +inputs: + playbook: # id of input + description: 'playbook to run' + required: true + default: 'playbook.yaml' + argsfile: # id of input + description: 'additional args file' + required: false +# outputs: +# time: # id of output +# description: 'The time we greeted you' +runs: + using: 'docker' + image: 'Dockerfile' + args: + - ${{ inputs.playbook }} + - ${{ inputs.argsfile }} \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..17d43c9 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# +# SPDX-License-Identifier: Apache-2.0 +# +set -xeuo pipefail +export INPUT_PLAYBOOK=$1 +export ARGSFILE=${2:-none} + +echo $INPUT_PLAYBOOK +echo $ARGSFILE + +echo $GITHUB_WORKSPACE +whoami +pwd + +export PYTHONPATH=/home/ibp-user/.local/lib/python3.9/site-packages +export HOME=/home/ibp-user +# cd ${HOME} + +export KUBECONFIG="${GITHUB_WORKSPACE}/_cfg/k8s_context.yaml" + +export IBP_ANSIBLE_LOG_FILENAME=${GITHUB_WORKSPACE}/_cfg/__ansible.log + +if [[ $ARGSFILE == "none" ]]; then + ansible-playbook -e ROOT=${GITHUB_WORKSPACE} ${GITHUB_WORKSPACE}/${INPUT_PLAYBOOK} +else + ansible-playbook -e ROOT=${GITHUB_WORKSPACE} --extra-vars "@${GITHUB_WORKSPACE}/${ARGSFILE}" ${GITHUB_WORKSPACE}/${INPUT_PLAYBOOK} +fi