Skip to content

Commit

Permalink
Merge pull request #80 from usrbinkat/feat/usrbinkat/devcontainer
Browse files Browse the repository at this point in the history
[feat] Boilerplate developer experience enhancements
  • Loading branch information
usrbinkat authored Nov 17, 2023
2 parents 869a665 + fbe3f61 commit 37d7b68
Show file tree
Hide file tree
Showing 48 changed files with 812 additions and 219 deletions.
1 change: 1 addition & 0 deletions .devcontainer
Submodule .devcontainer added at dce1e3
68 changes: 68 additions & 0 deletions .devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Reference:
// - https://containers.dev/features
// - https://containers.dev/implementors/features
// - https://code.visualstudio.com/docs/getstarted/settings
{
"name": "pulumi",
"image": "ghcr.io/pulumi/devcontainer",
"customizations": {
"vscode": {
"settings": [
"go.testTags", "all",
"go.buildTags", "all",
"editor.minimap.enabled", false,
"explorer.openEditors.visible", 1,
"editor.quickSuggestionsDelay", 0,
"editor.suggestSelection", "first",
"editor.snippetSuggestions", "top",
"editor.gotoLocation.multipleReferences", "goto",
"editor.gotoLocation.multipleDefinitions", "goto",
"editor.gotoLocation.multipleDeclarations", "goto",
"editor.gotoLocation.multipleImplementations", "goto",
"editor.gotoLocation.multipleTypeDefinitions", "goto",
"editor.terminal.integrated.shell.linux", "/usr/bin/zsh",
"files.trimTrailingWhitespace", true,
"files.trimFinalNewlines", true
],
"extensions": [
"golang.go",
"vscodevim.vim",
"github.copilot",
"ms-python.python",
"jetpack-io.devbox",
"redhat.vscode-yaml",
"esbenp.prettier-vscode",
"ms-vscode.makefile-tools",
"ms-azuretools.vscode-docker",
"github.vscode-pull-request-github",
"ms-vscode-remote.remote-containers",
"visualstudioexptteam.vscodeintellicode",
"bierner.markdown-preview-github-styles"
]
}
},
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": true,
"configureZshAsDefaultShell": true,
"installOhMyZsh": true,
"installOhMyZshConfig": true,
"upgradePackages": true,
"nonFreePackages": true,
"username": "vscode",
"userUid": "automatic",
"userGid": "automatic"
},
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
"moby": false,
"installDockerBuildx": true,
"version": "latest",
"dockerDashComposeVersion": "v2"
}
},
"postCreateCommand": "git submodule update --init --recursive",
"remoteUser": "vscode",
"forwardPorts": [1313],
"runArgs": ["--network=host"]
}

62 changes: 62 additions & 0 deletions .github/workflows/makefile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Makefile

on:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: '0 0 * * *'

jobs:
build:
runs-on: ubuntu-latest
container:
image: docker://ghcr.io/pulumi/devcontainer:latest
options: --user root
permissions:
contents: read
packages: read
actions: read
steps:
-
name: Checkout repository
uses: actions/checkout@v4
id: git
with:
submodules: 'recursive'
-
name: Unshallow clone for tags
id: tags
run: |
sudo chown -R $(whoami) /__w/pulumi-provider-boilerplate/pulumi-provider-boilerplate
git config --global --add safe.directory /__w/pulumi-provider-boilerplate/pulumi-provider-boilerplate
git fetch --prune --unshallow --tags
-
name: Build
id: build
run: |
make build
-
name: Install
id: install
run: |
set -ex
make install
-
name: PulumiUp
id: up
run: make up
-
name: PulumiDown
id: down
run: make down
-
name: Generate multi-language examples from yaml IaC program
id: examples
run: |
set -ex
make gen_examples
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule ".devcontainer"]
path = .devcontainer
url = https://github.com/pulumi/devcontainer
44 changes: 42 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ VERSION_PATH := ${PROVIDER_PATH}.Version
GOPATH := $(shell go env GOPATH)

WORKING_DIR := $(shell pwd)
EXAMPLES_DIR := ${WORKING_DIR}/examples/yaml
TESTPARALLELISM := 4

ensure::
Expand Down Expand Up @@ -65,7 +66,48 @@ python_sdk::
rm ./bin/setup.py.bak && \
cd ./bin && python3 setup.py build sdist

gen_examples: gen_go_example \
gen_nodejs_example \
gen_python_example \
gen_dotnet_example

gen_%_example:
rm -rf ${WORKING_DIR}/examples/$*
pulumi convert \
--cwd ${WORKING_DIR}/examples/yaml \
--logtostderr \
--generate-only \
--non-interactive \
--language $* \
--out ${WORKING_DIR}/examples/$*

define pulumi_login
export PULUMI_CONFIG_PASSPHRASE=asdfqwerty1234; \
pulumi login --local;
endef

up::
$(call pulumi_login) \
cd ${EXAMPLES_DIR} && \
pulumi stack init dev && \
pulumi stack select dev && \
pulumi config set name dev && \
pulumi up -y

down::
$(call pulumi_login) \
cd ${EXAMPLES_DIR} && \
pulumi stack select dev && \
pulumi destroy -y && \
pulumi stack rm dev -y

devcontainer::
git submodule update --init --recursive .devcontainer
git submodule update --remote --merge .devcontainer
cp -f .devcontainer/devcontainer.json .devcontainer.json

.PHONY: build

build:: provider dotnet_sdk go_sdk nodejs_sdk python_sdk

# Required for the codegen action that runs in pulumi/pulumi
Expand All @@ -76,11 +118,9 @@ lint::
pushd $$DIR && golangci-lint run -c ../.golangci.yml --timeout 10m && popd ; \
done


install:: install_nodejs_sdk install_dotnet_sdk
cp $(WORKING_DIR)/bin/${PROVIDER} ${GOPATH}/bin


GO_TEST := go test -v -count=1 -cover -timeout 2h -parallel ${TESTPARALLELISM}

test_all:: test_provider
Expand Down
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Pulumi Native Provider Boilerplate

This repository is a boilerplate showing how to create a native Pulumi provider.
This repository is a boilerplate showing how to create and locally test a native Pulumi provider.

## Authoring a Pulumi Native Provider

Expand All @@ -10,7 +10,9 @@ It implements a random number generator that you can [build and test out for you

### Prerequisites

Ensure the following tools are installed and present in your `$PATH`:
Prerequisites for this repository are already satisfied by the [Pulumi Devcontainer](https://github.com/pulumi/devcontainer) if you are using Github Codespaces, or VSCode.

If you are not using VSCode, you will need to ensure the following tools are installed and present in your `$PATH`:

* [`pulumictl`](https://github.com/pulumi/pulumictl#installation)
* [Go 1.21](https://golang.org/dl/) or 1.latest
Expand All @@ -21,7 +23,16 @@ Ensure the following tools are installed and present in your `$PATH`:
* [.NET](https://dotnet.microsoft.com/download)


### Creating and Initializing the Repository
### Build & test the boilerplate XYZ provider

1. Create a new Github CodeSpaces environment using this repository.
1. Open a terminal in the CodeSpaces environment.
1. Run `make build install` to build and install the provider.
1. Run `make gen_examples` to generate the example programs in `examples/` off of the source `examples/yaml` example program.
1. Run `make up` to run the example program in `examples/yaml`.
1. Run `make down` to tear down the example program.

### Creating a new provider repository

Pulumi offers this repository as a [GitHub template repository](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template) for convenience. From this repository:

Expand Down
Loading

0 comments on commit 37d7b68

Please sign in to comment.