- 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
Uh oh!
There was an error while loading.Please reload this page.
Changes from3 commits
172e7b8
c391303
5569c9b
c01ec95
fe22341
d82b10c
b3ec9aa
fa904b2
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -88,6 +88,14 @@ coder templates push --yes $CODER_TEMPLATE_NAME \ | ||
--name=$CODER_TEMPLATE_VERSION # Version name is optional | ||
``` | ||
You can also use the [coder/setup-action](https://github.com/coder/setup-coder) | ||
GitHub Action to install the Coder CLI and push new template versions. | ||
matifali marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
## Testing and Publishing Coder Templates in CI/CD | ||
See our [testing templates](../../../tutorials/testing-templates.md) tutorial | ||
for an example of how to test and publish Coder templates in a CI/CD pipeline. | ||
### Next steps | ||
- [Coder CLI Reference](../../../reference/cli/templates.md) | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -709,6 +709,11 @@ | ||
"description": "Learn how to clone Git repositories in Coder", | ||
"path": "./tutorials/cloning-git-repositories.md" | ||
}, | ||
{ | ||
"title": "Testing Templates", | ||
matifali marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
"description": "Learn how to test and publish Coder templates in a CI/CD pipeline", | ||
"path": "./tutorials/testing-templates.md" | ||
}, | ||
{ | ||
"title": "Use Apache as a Reverse Proxy", | ||
"description": "Learn how to use Apache as a reverse proxy", | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# Testing and Publishing Coder Templates in CI/CD | ||
matifali marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
<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 | ||
Before proceeding, ensure the following: | ||
- **Coder CLI** is installed and configured in your environment. | ||
- **Terraform CLI** is installed and available in your CI environment. | ||
- Access to your **Coder instance** with the appropriate | ||
[permissions](../admin/users/groups-roles.md#roles). | ||
matifali marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
## Example GitHub Action Workflow | ||
Below is an example workflow for testing and publishing a template using GitHub | ||
Actions. The workflow first validates the Terraform template, pushes the | ||
template to Coder without activating it, tests the template by creating a | ||
workspace, and then promotes the template version to active upon successful | ||
workspace creation. | ||
### Step-by-Step Process | ||
1. **Validate the Terraform template.** | ||
2. **Push the template to Coder without activating it.** | ||
3. **Test the template by creating a workspace.** | ||
4. **Promote the template version to active upon successful workspace | ||
creation.** | ||
matifali marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
### 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 | ||
run: | | ||
coder create -t $TEMPLATE_NAME --template-version ${{ steps.name.outputs.version_name }} test-${{ steps.name.outputs.version_name }} --yes | ||
matifali marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
- name: Run some example commands | ||
run: | | ||
coder config-ssh --yes | ||
# run some example commands | ||
coder ssh test-${{ steps.name.outputs.version_name }} -- make build | ||
- name: Promote template version | ||
if: success() | ||
run: | | ||
coder template version promote --template=$TEMPLATE_NAME --template-version=${{ steps.name.outputs.version_name }} --yes | ||
``` |