Skip to content
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
65 changes: 65 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Release

on:
push:
branches:
- main
- "+([0-9])?(.{+([0-9]),x}).x"
pull_request:
branches:
- main
types:
- opened
- synchronize
- reopened

permissions:
contents: write
issues: write
pull-requests: write

jobs:
validate:
name: Validate
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: "~> 1.12"

- name: Terraform Format Check
run: terraform -chdir=infra fmt -check -recursive

- name: Terraform Init
run: terraform -chdir=infra init -backend=false

- name: Terraform Validate
run: terraform -chdir=infra validate

release:
name: Semantic Release
needs: validate
if: github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22

- name: Install semantic-release plugins
run: npm install --no-save semantic-release @semantic-release/commit-analyzer @semantic-release/release-notes-generator @semantic-release/changelog @semantic-release/github @semantic-release/git conventional-changelog-conventionalcommits@7

- name: Run semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx semantic-release
29 changes: 29 additions & 0 deletions .releaserc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
branches:
- main
- "+([0-9])?(.{+([0-9]),x}).x" # maintenance branches: 1.x, 2.x, etc.

plugins:
- - "@semantic-release/commit-analyzer"
- preset: conventionalcommits
# This is a project scaffold, not a published artifact — only functional
# changes (feat/fix/perf) cut a release. docs/chore are recorded in the
# changelog (below) but do not trigger a release on their own.
- - "@semantic-release/release-notes-generator"
- preset: conventionalcommits
presetConfig:
types:
- type: feat
section: Features
- type: fix
section: Bug Fixes
- type: perf
section: Performance Improvements
- type: docs
section: Documentation
- - "@semantic-release/changelog"
- changelogFile: CHANGELOG.md
- - "@semantic-release/github"
- - "@semantic-release/git"
- assets:
- CHANGELOG.md
message: "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
63 changes: 47 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,56 +11,87 @@ Provides consistent labeling, naming conventions, and environment context for al
curl -sL https://raw.githubusercontent.com/ql4b/cloudless-infra/main/bootstrap | bash
```

or
or

```
```bash
# specify project name and directory
curl -sL https://raw.githubusercontent.com/ql4b/cloudless-infra/main/bootstrap | bash -s my-project infra
```

Then load the environment and `tf` wrapper, and apply:

```bash
# edit .env with your settings first (NAME, NAMESPACE, AWS_PROFILE, AWS_REGION)
source ./activate

export PATH="$(pwd):$PATH"
tf init
tf init
tf apply --auto-approve

tf output -json env | jq

tf output -json env | jq
```

## Manual Setup
## Manual Setup

```
```bash
# setup environment variables
cp .env.example .env

# edit variables in .env
```

## activate

`activate` sources `.env` and puts the repo root on `$PATH` (so the `tf`
wrapper is callable) for the current shell:

```bash
source ./activate
which tf
```

## tf wrapper

```
`tf` is a thin wrapper that sources `.env` and runs the pinned terraform binary
with `-chdir=infra`. If you prefer not to use `activate`, add the repo root to
`$PATH` yourself:

```bash
# add . to the $PATH
export PATH="$(pwd):$PATH"

# check tf is in the $PATH
which tf

tf varsion

tf version
```

## tf init
## tf init

```
```bash
tf init
```

## outputs

```
```bash
tf apply --auto-approve
tf output -json env | jq

tf output -json env | jq
```

## Releases

Releases are automated with [semantic-release](https://semantic-release.gitbook.io/)
driven by [Conventional Commits](https://www.conventionalcommits.org/). The
`.github/workflows/release.yml` workflow validates (`terraform fmt`, `init`,
`validate` against `infra/`) and, on push to `main`, cuts a version tag,
GitHub release, and `CHANGELOG.md` entry.

Commit messages determine the version bump:

- `fix:` / `perf:` → patch release
- `feat:` → minor release
- `feat!:` or a `BREAKING CHANGE:` footer → major release
- `docs:` / `chore:` → recorded in the changelog, no release on their own

This is a project scaffold (not a published module), so only functional
changes cut a release.
46 changes: 29 additions & 17 deletions bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,39 @@
# Bootstrap cloudless-infra into existing project
# Usage: curl -sL https://raw.githubusercontent.com/ql4b/cloudless-infra/main/bootstrap | bash

set -e
set -euo pipefail

# Preflight: required tools
for tool in curl tar; do
if ! command -v "$tool" >/dev/null 2>&1; then
echo "Error: '$tool' is required but not installed." >&2
exit 1
fi
done

PROJECT_NAME=${1:-$(basename "$PWD")}
BACKUP_FILES=("README.md" ".gitignore" ".env.example")
BACKUP_FILES=("README.md" ".env.example")
REMOVE_FILES=("bootstrap" "README.md" ".env.example")

echo "Bootstrapping cloudless-infra for project: $PROJECT_NAME"

# Backup common files
# Backup common files (plus .gitignore, handled explicitly as a merge below)


for f in "${BACKUP_FILES[@]}"; do
[ -f "$f" ] && cp "$f" "$f.bak"
done
[ -f .gitignore ] && cp .gitignore .gitignore.bak

# Download and extract without git history
if [ -n "$GITHUB_TOKEN" ]; then
if [ -n "${GITHUB_TOKEN:-}" ]; then
# Private repo with token
curl -sL -H "Authorization: token $GITHUB_TOKEN" \
curl -fsSL -H "Authorization: token $GITHUB_TOKEN" \
https://github.com/ql4b/cloudless-infra/archive/refs/heads/main.tar.gz | \
tar --strip-components=1 -xzf -
else
# Public repo
curl -sL https://github.com/ql4b/cloudless-infra/archive/refs/heads/main.tar.gz | \
curl -fsSL https://github.com/ql4b/cloudless-infra/archive/refs/heads/main.tar.gz | \
tar --strip-components=1 -xzf -
fi

Expand All @@ -36,12 +45,18 @@ fi
cat .env.example
} >> .env

# if .gitignore.bak exists, append to it
if [ -f .gitignore ]; then
# Merge .gitignore: host's original is the base, cloudless-infra's entries are
# appended (deduped, delimited) only if the host didn't already have them.
# If the host had no .gitignore, the extracted cloudless one stays as-is.
if [ -f .gitignore.bak ]; then
cloudless_ignore=$(cat .gitignore) # the just-extracted cloudless-infra one
{
echo -e "\n# cloudless-infra"
cat .gitignore
} >> .gitignore.bak
cat .gitignore.bak # host's original, intact, first
echo ""
echo "# cloudless-infra"
comm -13 <(sort -u .gitignore.bak) <(printf '%s\n' "$cloudless_ignore" | sort -u)
} > .gitignore
rm -f .gitignore.bak
fi

# Remove REMOVE_FILES
Expand All @@ -54,10 +69,7 @@ for f in "${BACKUP_FILES[@]}"; do
[ -f "$f.bak" ] && mv "$f.bak" "$f"
done

# Add . to the $PATH
export PATH="$(pwd):$PATH"
echo "export PATH=\"$(pwd):$PATH\"" >> ~/.zshrc

echo "✓ Cloudless infra bootstrapped in current directory"
echo "✓ Edit .env with your settings"
echo "✓ Run: ./tf init"
echo "✓ Edit .env with your settings (NAME, NAMESPACE, AWS_PROFILE, AWS_REGION)"
echo "✓ Load the environment and tf wrapper: source ./activate"
echo "✓ Then run: tf init"
2 changes: 1 addition & 1 deletion infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ locals {
module.label.namespace != "" ? module.label.namespace : null,
module.label.name != "" ? module.label.name : null
]))}"
pascal_prefix = replace(title(module.label.id), "/\\W+/", "")
pascal_prefix = replace(title(module.label.id), "/\\W+/", "")
}

18 changes: 9 additions & 9 deletions infra/output.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
output env {
value = {
profile = local.profile
region = local.region
namespace = module.label.namespace
name = module.label.name
id = module.label.id
account_id = local.account_id
}
output "env" {
value = {
profile = local.profile
region = local.region
namespace = module.label.namespace
name = module.label.name
id = module.label.id
account_id = local.account_id
}
}
12 changes: 9 additions & 3 deletions infra/terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
# be bootstrapped according to the simple yet essential procedure in
# https://github.com/cloudposse/terraform-aws-tfstate-backend#usage
module "terraform_state_backend" {
source = "cloudposse/tfstate-backend/aws"
version = "1.7.0"
enabled = false
source = "cloudposse/tfstate-backend/aws"
version = "1.9.0"
enabled = false

profile = local.profile

namespace = module.label.namespace
name = module.label.name
attributes = ["tfstate"]

# S3 native state locking (use_lockfile) — the current strategy.
# Requires Terraform >= 1.10 (satisfied by required_version ~> 1.12).
# Replaces the deprecated DynamoDB lock table.
s3_state_lock_enabled = true
dynamodb_enabled = false

terraform_backend_config_file_path = "."
terraform_backend_config_file_name = "backend.tf"
force_destroy = true
Expand Down
10 changes: 5 additions & 5 deletions infra/variables.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
variable "name" {
type = string
type = string
default = null
}

variable "namespace" {
type = string
type = string
default = null
}

variable "profile" {
type = string
type = string
default = null
}

variable "region" {
type = string
default = null
type = string
default = null
}
Loading