Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor for template use case #38

Merged
merged 5 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .devcontainer.json

This file was deleted.

38 changes: 15 additions & 23 deletions devcontainer.json → .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Reference:
// - https://containers.dev/features
// - https://containers.dev/implementors/features
// - https://containers.dev/implementors/json_reference
// - https://code.visualstudio.com/docs/getstarted/settings
{
"name": "pulumi-devcontainer",
"image": "ghcr.io/pulumi/devcontainer:latest",
"name": "konductor",
//"image": "ghcr.io/pulumi/devcontainer",
"dockerFile": ".github/docker/Dockerfile",
"customizations": {
"vscode": {
"settings": {
Expand Down Expand Up @@ -41,47 +43,37 @@
"editor.gotoLocation.multipleImplementations": "goto",
"editor.gotoLocation.multipleTypeDefinitions": "goto",
"editor.terminal.integrated.shell.linux": "/usr/bin/fish",
"terminal.integrated.sendKeybindingsToShell": true,
"terminal.integrated.fontFamily": "FiraMono Nerd Font Mono",
"terminal.integrated.shell.linux": "/usr/bin/fish",
"terminal.integrated.sendKeybindingsToShell": true,
"workbench.colorTheme": "Dracula Soft",
"explorer.openEditors.visible": 1,
"files.trimTrailingWhitespace": true,
"files.trimFinalNewlines": true
},
"extensions": [
"golang.go",
"github.copilot",
"vscodevim.vim",
"github.copilot",
"ms-python.python",
"redhat.vscode-yaml",
"esbenp.prettier-vscode",
"ms-vscode.makefile-tools",
"ms-azuretools.vscode-docker",
"ms-vsliveshare.vsliveshare",
"github.vscode-github-actions",
"ms-vscode.vscode-typescript-next",
"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": {
"username": "vscode",
"userGid": "automatic",
"userUid": "automatic",
"upgradePackages": false,
"nonFreePackages": true
},
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
"installDockerBuildx": true,
"dockerDashComposeVersion": "v2",
"version": "latest",
"moby": false
}
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}
},
"postCreateCommand": "git submodule update --init --recursive; direnv allow",
"remoteUser": "vscode",
"forwardPorts": [1313, 2222, 6000, 7681, 8080],
"runArgs": ["--network=host"]
"postCreateCommand": "true",
"mounts": ["source=dind-var-lib-docker,target=/var/lib/docker,type=volume"],
"runArgs": ["--init", "--privileged", "--network=host"],
"overrideCommand": false
}

File renamed without changes.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export FOO="bar"
1 change: 1 addition & 0 deletions .github/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM ghcr.io/pulumi/devcontainer
2 changes: 1 addition & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
image: ghcr.io/pulumi/devcontainer
image: ghcr.io/pulumi/devcontainer
16 changes: 0 additions & 16 deletions .vscode/settings.json

This file was deleted.

71 changes: 71 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# --- Global Variables ---
PULUMI_STACK := echo $GITHUB_REPOSITORY | awk -F '[/]' '{print $2}'
GITHUB_REPOSITORY_STRING := $(shell echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]')
DOCKER_IMAGE_NAME := ghcr.io/${GITHUB_REPOSITORY_STRING}:latest
# --- Help ---
# This section provides a default help message displaying all available commands
help:
@echo "Available commands:"
@echo " update Update the .github/devcontainer submodule"
@echo " login Log in to Pulumi"
@echo " esc Run a Pulumi ESC environment"
@echo " up Deploy Pulumi infrastructure"
@echo " act Install the GitHub 'gh-act' extension"
@echo " test Run all tests"

# --- Docker Build ---
# Build the Docker image
build:
@echo "Building Docker image..."
clear
docker build --progress plain --load --pull --build-arg GITHUB_TOKEN="${GITHUB_TOKEN}" --tag ${DOCKER_IMAGE_NAME} -f ./docker/Dockerfile ./docker
@echo "Docker image built."

# --- GitHub Actions ---
# Install & Run the GitHub 'gh-act' extension for local testing of GitHub Actions
act:
@echo "Installing & Running 'act' Github Actions Workflow Testing..."
gh extension install nektos/gh-act || true
gh act -s GITHUB_TOKEN=${GITHUB_TOKEN} -s ACTIONS_RUNTIME_TOKEN=${GITHUB_TOKEN} -s GHA_GITHUB_TOKEN=${GITHUB_TOKEN}
@echo "Github Workflow Complete."

# --- Pulumi Commands ---
# Log in to Pulumi
pulumi-login:
@echo "Logging in to Pulumi..."
pulumi login
@echo "Login successful."

# Deploy Pulumi infrastructure
pulumi-up:
@echo "Deploying Pulumi infrastructure..."
pulumi up --stack $(PULUMI_STACK)
@echo "Deployment complete."

# Run a Pulumi ESC environment
pulumi-esc-env:
@echo "Running Pulumi ESC environment..."
# Replace the below command with the actual command to run the Pulumi ESC environment
pulumi esc env open --stack $(PULUMI_STACK)
@echo "Pulumi ESC environment running."

# --- Devcontainer Management ---
# Update the .github/devcontainer submodule
update-devcontainer:
@echo "Updating .github/devcontainer submodule..."
git submodule update --init --recursive .github/devcontainer
@echo "Update complete."

# --- Testing ---
# Add your testing scripts here
test:
@echo "Running tests..."
# Add commands to run your tests
@echo "Testing complete."

# --- Default Command ---
# Default command when running 'make' without arguments
all: help

# Note: Each command is fully implemented with the necessary steps for each task.
# This Makefile is designed to be both functional and educational.
5 changes: 0 additions & 5 deletions Makefile.example

This file was deleted.

68 changes: 43 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,55 +1,73 @@
# Pulumi Dev Container
[![Pulumi](https://img.shields.io/badge/pulumi-v3.101.1-blueviolet)](https://www.pulumi.com/docs/get-started/install/) [![Kubectl](https://img.shields.io/badge/kubectl-v1.29.0-blueviolet)](https://kubernetes.io/docs/tasks/tools/install-kubectl/) [![Docker](https://img.shields.io/badge/docker-v24.0.7-blueviolet)](https://docs.docker.com/get-docker/) [![Kind](https://img.shields.io/badge/kind-v0.20.0-blueviolet)](https://kind.sigs.k8s.io/docs/user/quick-start/) [![Helm](https://img.shields.io/badge/helm-v3.13.3-blueviolet)](https://helm.sh/docs/intro/install/)
[![License](https://img.shields.io/github/license/usrbinkat/iac-mesh-pac)]() [![ghcr.io/pulumi/devcontainer](https://github.com/pulumi/devcontainer/actions/workflows/build.yaml/badge.svg?branch=main)](https://github.com/pulumi/devcontainer/actions/workflows/build.yaml)
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/pulumi/devcontainer?quickstart=1)

### [![ghcr.io/pulumi/devcontainer](https://github.com/pulumi/devcontainer/actions/workflows/build.yaml/badge.svg?branch=main)](https://github.com/pulumi/devcontainer/actions/workflows/build.yaml)
This is a [Github Template Repository](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template) which provides a Pulumi [Devcontainer](https://code.visualstudio.com/docs/devcontainers/containers) together with GitOps ready boilerplate for quickly starting new Pulumi IaC projects.

This repository is designed with deep [VS Code](https://code.visualstudio.com) integration to automate Pulumi IaC and Provider development dependencies and prerequisites as much as possible using [Dev Containers](https://containers.dev/) to prepare your development environment, or even just run your development directly in the browser with [Github CodeSpaces](https://github.com/features/codespaces).
The Pulumi [Devcontainer](https://code.visualstudio.com/docs/devcontainers/containers) is designed with deep [VS Code](https://code.visualstudio.com) and [Github Codespaces](https://github.com/features/codespaces) integration to streamline a common Pulumi IaC and Provider development environment. dependencies and prerequisites as much as possible using [Dev Containers](https://containers.dev/) to prepare your development environment, or even just run your development directly in the browser with [Github CodeSpaces](https://github.com/features/codespaces).

![CodeSpaces Screenshot](./.github/assets/codespaces.png)

# Getting Started

There are 3 ways to get started:
With multiple ways to get started, it is a good idea to briefly review:

1. [Git Submodule](#git-submodule)
1. [Github CodeSpaces](#github-codespaces)
1. [VS Code Dev Container](#vs-code-dev-container)
- [Getting Started](#getting-started)
- [Git Submodule](#git-submodule)
- [Github CodeSpaces](#github-codespaces)
- [VS Code Dev Container](#vs-code-dev-container)
- [First time setup](#first-time-setup)
- [Pulumi Dev Container](#pulumi-dev-container)

# Git Submodule
# Github CodeSpaces

The pulumi Dev Container repository can be added as a submodule to your project to provide an easy and consistent development environment.
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/pulumi/devcontainer?quickstart=1)

To add this repository as a submodule to your project, run the following commands:
Codespaces is the easiest way to get started quickly. Simply click the button above to open this repository in a new Codespace and then follow the [First time setup](#first-time-setup) instructions below.

```bash
git submodule add https://github.com/pulumi/devcontainer .devcontainer
git submodule update --init --recursive .devcontainer
```
> Fig 1. How to open project in CodeSpaces
![How to open repository in CodeSpaces](./.github/assets/gh-open-codespaces.png)

To update the devcontainer submodule in consuming repos:
## First time setup

1. Pulumi Login

```bash
git submodule update --remote --merge .devcontainer
pulumi login
```

After the submodule is added, you can open your project in VS Code and it will automatically detect the Dev Container configuration and prompt you to open the project in a container, or you can open the project in Github CodeSpaces.
> Fig 2.b pulumi login
![Pulumi login](./.github/assets/pulumi-login.png)
![Pulumi login complete](./.github/assets/pulumi-login-complete.png)

# Github CodeSpaces
2. Create a new stack

> Fig 1. How to open project in CodeSpaces
![How to open repository in CodeSpaces](./.github/assets/gh-open-codespaces.png)
```bash
pulumi new
pulumi stack init
```

# VS Code Dev Container

To use the Dev Container in VS Code, you will need to install the [Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension, and follow the [official tutorial here](https://code.visualstudio.com/docs/devcontainers/tutorial) to begin.

## First time setup
# Git Submodule

1. Pulumi Login
The pulumi Dev Container repository can be added as a submodule to an existing project to provide an easy and consistent development environment that is maintained upstream.

To add this repository as a submodule to your project, run the following commands:

```bash
pulumi login
git submodule add https://github.com/pulumi/devcontainer .github/devcontainer
git submodule update --init --recursive .github/devcontainer
mkdir .devcontainer && cp .github/devcontainer/.devcontainer/* .devcontainer/
```

> Fig 2.b pulumi login
![Pulumi login](./.github/assets/pulumi-login.png)
![Pulumi login complete](./.github/assets/pulumi-login-complete.png)
To update the devcontainer submodule in consuming repos:

```bash
git submodule update --remote --merge .github/devcontainer
```

After the submodule is added, you can open your project in VS Code and it will automatically detect the Dev Container configuration and prompt you to open the project in a container, or you can open the project in Github CodeSpaces.
File renamed without changes.
Loading