- Notifications
You must be signed in to change notification settings - Fork928
feat(site): add create template from scratch#12082
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
14 commits Select commitHold shift + click to select a range
811872f
Add scratch as starter template
BrunoQuaresma4c60dcc
Add create from scratch flow
BrunoQuaresmacdb36a8
Don't show scratch template
BrunoQuaresma2e756c4
Add stories for create template button
BrunoQuaresma0609511
Test if scratch template is not displayed
BrunoQuaresmaf8a6efc
Add test for scratch flow
BrunoQuaresma9ee2112
Fix typo
BrunoQuaresma6ff64f4
Update golden files
BrunoQuaresmad9581d0
Fix tests
BrunoQuaresma7c24744
Fix e2e tests
BrunoQuaresma914a724
Apply suggestions from code review
BrunoQuaresma63bd718
Fix format
BrunoQuaresma8389b33
Only uses coder_script to def scripts
BrunoQuaresma66c8e78
Fix gen files
BrunoQuaresmaFile 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
2 changes: 1 addition & 1 deletioncli/testdata/coder_templates_init_--help.golden
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
6 changes: 3 additions & 3 deletionsdocs/cli/templates_init.md
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
9 changes: 9 additions & 0 deletionsexamples/examples.gen.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
1 change: 1 addition & 0 deletionsexamples/examples.go
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
12 changes: 12 additions & 0 deletionsexamples/templates/scratch/README.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,12 @@ | ||
--- | ||
display_name: Scratch | ||
description: A minimal starter template for Coder | ||
icon: ../../../site/static/emojis/1f4e6.png | ||
maintainer_github: coder | ||
verified: true | ||
tags: [] | ||
--- | ||
# A minimal Scaffolding for a Coder Template | ||
Use this starter template as a basis to create your own unique template from scratch. |
62 changes: 62 additions & 0 deletionsexamples/templates/scratch/main.tf
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,62 @@ | ||
terraform { | ||
required_providers { | ||
coder = { | ||
source = "coder/coder" | ||
} | ||
} | ||
} | ||
data "coder_provisioner" "me" {} | ||
data "coder_workspace" "me" {} | ||
resource "coder_agent" "main" { | ||
arch = data.coder_provisioner.me.arch | ||
os = data.coder_provisioner.me.os | ||
metadata { | ||
display_name = "CPU Usage" | ||
key = "0_cpu_usage" | ||
script = "coder stat cpu" | ||
interval = 10 | ||
timeout = 1 | ||
} | ||
metadata { | ||
display_name = "RAM Usage" | ||
key = "1_ram_usage" | ||
script = "coder stat mem" | ||
interval = 10 | ||
timeout = 1 | ||
} | ||
} | ||
# Use this to set environment variables in your workspace | ||
# details: https://registry.terraform.io/providers/coder/coder/latest/docs/resources/env | ||
resource "coder_env" "welcome_message" { | ||
agent_id = coder_agent.main.id | ||
name = "WELCOME_MESSAGE" | ||
value = "Welcome to your Coder workspace!" | ||
} | ||
# Adds code-server | ||
# See all available modules at https://registry.coder.com | ||
module "code-server" { | ||
source = "registry.coder.com/modules/code-server/coder" | ||
version = "1.0.2" | ||
agent_id = coder_agent.main.id | ||
} | ||
# Runs a script at workspace start/stop or on a cron schedule | ||
# details: https://registry.terraform.io/providers/coder/coder/latest/docs/resources/script | ||
resource "coder_script" "startup_script" { | ||
agent_id = coder_agent.main.id | ||
display_name = "Startup Script" | ||
script = <<-EOF | ||
#!/bin/sh | ||
set -e | ||
# Run programs at workspace startup | ||
EOF | ||
run_on_start = true | ||
start_blocks_login = true | ||
} |
2 changes: 1 addition & 1 deletionsite/e2e/helpers.ts
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
4 changes: 2 additions & 2 deletionssite/src/pages/CreateTemplatePage/CreateTemplatePage.test.tsx
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
11 changes: 8 additions & 3 deletionssite/src/pages/CreateTemplatePage/CreateTemplatePage.tsx
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
11 changes: 9 additions & 2 deletionssite/src/pages/CreateTemplatePage/DuplicateTemplateView.tsx
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
11 changes: 9 additions & 2 deletionssite/src/pages/CreateTemplatePage/ImportStarterTemplateView.tsx
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
12 changes: 10 additions & 2 deletionssite/src/pages/CreateTemplatePage/UploadTemplateView.tsx
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
59 changes: 59 additions & 0 deletionssite/src/pages/StarterTemplatesPage/StarterTemplatesPage.test.tsx
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,59 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import StarterTemplatesPage from "./StarterTemplatesPage"; | ||
import { AppProviders } from "App"; | ||
import { RouterProvider, createMemoryRouter } from "react-router-dom"; | ||
import { RequireAuth } from "contexts/auth/RequireAuth"; | ||
import { rest } from "msw"; | ||
import { | ||
MockTemplateExample, | ||
MockTemplateExample2, | ||
} from "testHelpers/entities"; | ||
import { server } from "testHelpers/server"; | ||
test("does not display the scratch template", async () => { | ||
server.use( | ||
rest.get( | ||
"api/v2/organizations/:organizationId/templates/examples", | ||
(req, res, ctx) => { | ||
return res( | ||
ctx.status(200), | ||
ctx.json([ | ||
MockTemplateExample, | ||
MockTemplateExample2, | ||
{ | ||
...MockTemplateExample, | ||
id: "scratch", | ||
name: "Scratch", | ||
description: "Create a template from scratch", | ||
}, | ||
]), | ||
); | ||
}, | ||
), | ||
); | ||
render( | ||
<AppProviders> | ||
<RouterProvider | ||
router={createMemoryRouter( | ||
[ | ||
{ | ||
element: <RequireAuth />, | ||
children: [ | ||
{ | ||
path: "/starter-templates", | ||
element: <StarterTemplatesPage />, | ||
}, | ||
], | ||
}, | ||
], | ||
{ initialEntries: ["/starter-templates"] }, | ||
)} | ||
/> | ||
</AppProviders>, | ||
); | ||
await screen.findByText(MockTemplateExample.name); | ||
screen.getByText(MockTemplateExample2.name); | ||
expect(screen.queryByText("Scratch")).not.toBeInTheDocument(); | ||
}); |
8 changes: 7 additions & 1 deletionsite/src/pages/StarterTemplatesPage/StarterTemplatesPage.tsx
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
22 changes: 22 additions & 0 deletionssite/src/pages/TemplatesPage/CreateTemplateButton.stories.tsx
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,22 @@ | ||
import { CreateTemplateButton } from "./CreateTemplateButton"; | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { userEvent, screen } from "@storybook/test"; | ||
const meta: Meta<typeof CreateTemplateButton> = { | ||
title: "pages/TemplatesPage/CreateTemplateButton", | ||
component: CreateTemplateButton, | ||
}; | ||
export default meta; | ||
type Story = StoryObj<typeof CreateTemplateButton>; | ||
export const Close: Story = {}; | ||
export const Open: Story = { | ||
play: async ({ step }) => { | ||
const user = userEvent.setup(); | ||
await step("click on trigger", async () => { | ||
await user.click(screen.getByRole("button")); | ||
}); | ||
}, | ||
}; |
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.