diff --git a/.github/workflows/publish-devcontainer-features.yml b/.github/workflows/publish-devcontainer-features.yml new file mode 100644 index 00000000..40dff976 --- /dev/null +++ b/.github/workflows/publish-devcontainer-features.yml @@ -0,0 +1,34 @@ +name: "Publish dev container features" +on: + push: + branches: + - main + paths: + - .github/workflows/validate-devcontainer-feature.yml + - devcontainer/features/** + pull_request: + branches: + - main + paths: + - .github/workflows/validate-devcontainer-feature.yml + - devcontainer/features/** + +jobs: + deploy: + if: ${{ github.ref == 'refs/heads/main' }} + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v3 + + - name: "Publish Features" + uses: devcontainers/action@v1.4.0 + with: + publish-features: "true" + base-path-to-features: "./devcontainer/features" + generate-docs: "false" + + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/validate-devcontainer-features.yml b/.github/workflows/validate-devcontainer-features.yml new file mode 100644 index 00000000..bb2bd9ab --- /dev/null +++ b/.github/workflows/validate-devcontainer-features.yml @@ -0,0 +1,26 @@ +name: "Validate devcontainer-feature.json files" +on: + push: + branches: + - main + paths: + - .github/workflows/validate-devcontainer-feature.yml + - devcontainer/features/** + pull_request: + branches: + - main + paths: + - .github/workflows/validate-devcontainer-feature.yml + - devcontainer/features/** + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: "Validate devcontainer-feature.json files" + uses: devcontainers/action@v1.4.0 + with: + validate-only: "true" + base-path-to-features: "./devcontainer/features" diff --git a/devcontainer/features/ansible/README.md b/devcontainer/features/ansible/README.md new file mode 100644 index 00000000..d004f58d --- /dev/null +++ b/devcontainer/features/ansible/README.md @@ -0,0 +1 @@ +Feature to run an ansible playbook on container start diff --git a/devcontainer/features/ansible/devcontainer-feature.json b/devcontainer/features/ansible/devcontainer-feature.json new file mode 100644 index 00000000..7a8c7cf8 --- /dev/null +++ b/devcontainer/features/ansible/devcontainer-feature.json @@ -0,0 +1,15 @@ +{ + "name": "Run an ansible playbook", + "id": "ansible", + "version": "1.0.0", + "description": "Runs an ansible playbook and installs pre-requests for plays/roles from the marinatedconcrete repo", + "options": { + "playbook": { + "type": "string", + "proposals": ["site.yml"], + "default": "site.yml", + "description": "Select a play to run on container start" + } + }, + "installsAfter": ["ghcr.io/devcontainers/features/common-utils"] +} diff --git a/devcontainer/features/ansible/install.sh b/devcontainer/features/ansible/install.sh new file mode 100755 index 00000000..c6047ea9 --- /dev/null +++ b/devcontainer/features/ansible/install.sh @@ -0,0 +1,25 @@ +#!/bin/sh +set -e + +if [ -f requirements.txt ]; then + # Install pip to install ansible & kubernetes modules + if ! command -v pip; then + sudo apt update + sudo apt install -y --no-install-recommends python3-pip + fi + pip install -r requirements.txt +fi + +# Now that pip is setup, install Ansible Galaxy modules +if [ -f requirements.yml ]; then + ansible-galaxy install -r requirements.yml +fi + +# sshpass for initial node provisioning +if ! command -v sshpass; then + sudo apt update + sudo apt install -y --no-install-recommends sshpass +fi + +PLAYBOOK=${PLAYBOOK:-undefined} +ansible-playbook "$PLAYBOOK" \ No newline at end of file