Keeping Templates up to date
Keeping Coder templates up to date
Templates in Coder help keep each developer's workspace consistent. When a new template version is created (e.g. with a newer version of Java or more CPU cores), all developers are notified to update their workspaces.
Updating an existing Coder template is easy. You can make changes to the template directly locally and then push the changes to Coder server in multiple ways.
To keep your Coder templates up to date, you need to push the changes to Coder server. A user with a template-admin
or owner
role can update templates.
Using the Coder CLI
You can use the Coder CLI to push the changes to the template to the Coder server. This is the easiest way to update the template.
- Install the Coder CLI. See Installing the Coder CLI for more information.
- Run the following command to push the changes to the template to the Coder server.
coder templates push <template-name>
This will push the changes to the template to the Coder server, assign a random name to the template, and create a new template version. All users will then see the Update button on their workspace.
Using CI/CD
You can also use CI/CD to push the changes to the template to the Coder server. This is useful if you want to automate the process of updating the template. This is the preferred method if you have a version control system for your templates and want your developers to update the template by creating a pull request.
- Create a new repository for your template(s).
- Create a new workflow in your repository. See Creating a workflow file for more information.
- Create a new personal access token with the
template-admin
orowner
role. and add it to the repository action secrets with the nameCODER_SESSION_TOKEN
.
coder tokens create --lifetime 8760h0m0s
- Add the following steps to the workflow.
name: Push template to coder server
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
jobs:
deploy_template:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
with:
submodules: true
- name: Get short commit SHA # to use as template version name
id: vars
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
- name: "Install latest Coder"
run: |
curl -L https://coder.com/install.sh | sh
- name: "Push template"
run: |
coder templates push <template-name> /--directory ./<template-directory> /
--name ${{ steps.vars.outputs.sha_short }} /
--yes
env:
# Consumed by Coder CLI
CODER_URL: https://coder.example.com
CODER_SESSION_TOKEN: ${{ secrets.CODER_SESSION_TOKEN }}
or you can use the Update Coder Template action from the GitHub marketplace.
name: Update Coder Template
on:
push:
branches:
- master
pull_request:
branches:
- main
workflow_dispatch:
jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Get latest commit hash
id: latest_commit
run: echo "::set-output name=hash::$(git rev-parse --short HEAD)"
- name: Update Coder Template
uses: matifali/[email protected]
with:
CODER_TEMPLATE_NAME: "template-name"
CODER_TEMPLATE_DIR: "template-directory"
CODER_URL: "https://coder.example.com"
CODER_TEMPLATE_VERSION: "${{ steps.latest_commit.outputs.hash }}"
CODER_SESSION_TOKEN: ${{ secrets.CODER_SESSION_TOKEN }}
- Push the changes to the template to the git repository. This will trigger the workflow and push the changes to the template to the Coder server.
See Coder's dogfood example workflow here.
See a community workflow that uses Update Coder Template action here