- Notifications
You must be signed in to change notification settings - Fork914
docs: add guide for CI/CD template testing#15528
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
8 commits Select commitHold shift + click to select a range
172e7b8
docs: add guide for CI/CD template testing
matifalic391303
Update manifest to include testing templates guide
matifali5569c9b
Enhance template testing with SSH command execution
matifalic01ec95
Apply suggestions from code review
matifalife22341
Merge branch 'main' into atif/test-templates
matifalid82b10c
Update template testing workflow to ensure cleanup
matifalib3ec9aa
`make fmt`
matifalifa904b2
docs: update CLI instructions and link setup-coder
matifaliFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
10 changes: 8 additions & 2 deletionsdocs/admin/templates/managing-templates/change-management.md
matifali marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page.
matifali marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletionsdocs/manifest.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletionsdocs/tutorials/testing-templates.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# Test and Publish Coder Templates Through CI/CD | ||
<div> | ||
<a href="https://github.com/matifali" style="text-decoration: none; color: inherit;"> | ||
<span style="vertical-align:middle;">Muhammad Atif Ali</span> | ||
<img src="https://github.com/matifali.png" width="24px" height="24px" style="vertical-align:middle; margin: 0px;"/> | ||
</a> | ||
</div> | ||
November 15, 2024 | ||
--- | ||
## Overview | ||
This guide demonstrates how to test and publish Coder templates in a Continuous | ||
Integration (CI) pipeline using the | ||
[coder/setup-action](https://github.com/coder/setup-coder). This workflow | ||
ensures your templates are validated, tested, and promoted seamlessly. | ||
## Prerequisites | ||
- Install and configure Coder CLI in your environment. | ||
- Install Terraform CLI in your CI environment. | ||
- Create a [headless user](../admin/users/headless-auth.md) with the | ||
[user roles and permissions](../admin/users/groups-roles.md#roles) to manage | ||
templates and run workspaces. | ||
## Creating the headless user | ||
```shell | ||
coder users create \ | ||
--username machine-user \ | ||
--email machine-user@example.com \ | ||
--login-type none | ||
coder tokens create --user machine-user --lifetime 8760h | ||
# Copy the token and store it in a secret in your CI environment with the name `CODER_SESSION_TOKEN` | ||
``` | ||
## Example GitHub Action Workflow | ||
This example workflow tests and publishes a template using GitHub Actions. | ||
The workflow: | ||
1. Validates the Terraform template. | ||
1. Pushes the template to Coder without activating it. | ||
1. Tests the template by creating a workspace. | ||
1. Promotes the template version to active upon successful workspace creation. | ||
### Workflow File | ||
Save the following workflow file as `.github/workflows/publish-template.yaml` in | ||
your repository: | ||
```yaml | ||
name: Test and Publish Coder Template | ||
on: | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
jobs: | ||
test-and-publish: | ||
runs-on: ubuntu-latest | ||
env: | ||
TEMPLATE_NAME: "my-template" | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
- name: Set up Terraform | ||
uses: hashicorp/setup-terraform@v2 | ||
with: | ||
terraform_version: latest | ||
- name: Set up Coder CLI | ||
uses: coder/setup-action@v1 | ||
with: | ||
access_url: "https://coder.example.com" | ||
coder_session_token: ${{ secrets.CODER_SESSION_TOKEN }} | ||
- name: Validate Terraform template | ||
run: terraform validate | ||
- name: Get short commit SHA to use as template version name | ||
id: name | ||
run: echo "version_name=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | ||
- name: Get latest commit title to use as template version description | ||
id: message | ||
run: | ||
echo "pr_title=$(git log --format=%s -n 1 ${{ github.sha }})" >> | ||
$GITHUB_OUTPUT | ||
- name: Push template to Coder | ||
run: | | ||
coder templates push $TEMPLATE_NAME --activate=false --name ${{ steps.name.outputs.version_name }} --message "${{ steps.message.outputs.pr_title }}" --yes | ||
- name: Create a test workspace and run some example commands | ||
run: | | ||
coder create -t $TEMPLATE_NAME --template-version ${{ steps.name.outputs.version_name }} test-${{ steps.name.outputs.version_name }} --yes | ||
coder config-ssh --yes | ||
# run some example commands | ||
coder ssh test-${{ steps.name.outputs.version_name }} -- make build | ||
- name: Delete the test workspace | ||
if: always() | ||
run: coder delete test-${{ steps.name.outputs.version_name }} --yes | ||
- name: Promote template version | ||
if: success() | ||
run: | | ||
coder template version promote --template=$TEMPLATE_NAME --template-version=${{ steps.name.outputs.version_name }} --yes | ||
``` |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.