Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 0 additions & 8 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ type Options struct {

type Metadata struct {
WireguardAddresses []netaddr.IPPrefix `json:"addresses"`
OwnerEmail string `json:"owner_email"`
OwnerUsername string `json:"owner_username"`
EnvironmentVariables map[string]string `json:"environment_variables"`
StartupScript string `json:"startup_script"`
Directory string `json:"directory"`
Expand Down Expand Up @@ -386,12 +384,6 @@ func (a *agent) createCommand(ctx context.Context, rawCommand string, env []stri
// If using backslashes, it's unable to find the executable.
unixExecutablePath := strings.ReplaceAll(executablePath, "\\", "/")
cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_SSH_COMMAND=%s gitssh --`, unixExecutablePath))
// These prevent the user from having to specify _anything_ to successfully commit.
// Both author and committer must be set!
cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_AUTHOR_EMAIL=%s`, metadata.OwnerEmail))
cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_COMMITTER_EMAIL=%s`, metadata.OwnerEmail))
cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_AUTHOR_NAME=%s`, metadata.OwnerUsername))
cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_COMMITTER_NAME=%s`, metadata.OwnerUsername))

// Load environment variables passed via the agent.
// These should override all variables we manually specify.
Expand Down
1 change: 1 addition & 0 deletions coderd/provisionerdaemons.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ func (server *provisionerdServer) AcquireJob(ctx context.Context, _ *proto.Empty
WorkspaceTransition: transition,
WorkspaceName: workspace.Name,
WorkspaceOwner: owner.Username,
WorkspaceOwnerEmail: owner.Email,
WorkspaceId: workspace.ID.String(),
WorkspaceOwnerId: owner.ID.String(),
},
Expand Down
34 changes: 0 additions & 34 deletions coderd/workspaceagents.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,38 +129,6 @@ func (api *API) workspaceAgentMetadata(rw http.ResponseWriter, r *http.Request)
})
return
}
resource, err := api.Database.GetWorkspaceResourceByID(r.Context(), workspaceAgent.ResourceID)
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error fetching workspace resources.",
Detail: err.Error(),
})
return
}
build, err := api.Database.GetWorkspaceBuildByJobID(r.Context(), resource.JobID)
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error fetching workspace build.",
Detail: err.Error(),
})
return
}
workspace, err := api.Database.GetWorkspaceByID(r.Context(), build.WorkspaceID)
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error fetching workspace.",
Detail: err.Error(),
})
return
}
owner, err := api.Database.GetUserByID(r.Context(), workspace.OwnerID)
if err != nil {
httpapi.Write(rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error fetching workspace owner.",
Detail: err.Error(),
})
return
}

ipp, ok := netaddr.FromStdIPNet(&workspaceAgent.WireguardNodeIPv6.IPNet)
if !ok {
Expand All @@ -173,8 +141,6 @@ func (api *API) workspaceAgentMetadata(rw http.ResponseWriter, r *http.Request)

httpapi.Write(rw, http.StatusOK, agent.Metadata{
WireguardAddresses: []netaddr.IPPrefix{ipp},
OwnerEmail: owner.Email,
OwnerUsername: owner.Username,
EnvironmentVariables: apiAgent.EnvironmentVariables,
StartupScript: apiAgent.StartupScript,
Directory: apiAgent.Directory,
Expand Down
6 changes: 6 additions & 0 deletions examples/templates/aws-linux/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ resource "coder_agent" "dev" {
arch = "amd64"
auth = "aws-instance-identity"
os = "linux"
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
}

locals {
Expand Down
6 changes: 6 additions & 0 deletions examples/templates/aws-windows/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ resource "coder_agent" "dev" {
arch = "amd64"
auth = "aws-instance-identity"
os = "windows"
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
}

locals {
Expand Down
6 changes: 6 additions & 0 deletions examples/templates/do-linux/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ data "coder_workspace" "me" {}
resource "coder_agent" "dev" {
os = "linux"
arch = "amd64"
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add this to our docs (which you can do in this PR too), but we shouldn't do it in all templates. I think it could give the perception that this is mandatory when it certainly isn't.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. In that case I'd lean towards including it in the docker and docker-code-server templates, since those are the ones that are most likely to be used for a "quickstart", and removing it from the others. I'll add documentation as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with that. Makes sense to me!

}

resource "digitalocean_volume" "home_volume" {
Expand Down
6 changes: 6 additions & 0 deletions examples/templates/docker-code-server/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ resource "coder_agent" "dev" {
arch = var.docker_arch
os = "linux"
startup_script = "code-server --auth none"
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
}

resource "coder_app" "code-server" {
Expand Down
8 changes: 7 additions & 1 deletion examples/templates/docker-image-builds/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ data "coder_workspace" "me" {
resource "coder_agent" "dev" {
arch = var.step2_arch
os = "linux"
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
}

variable "docker_image" {
Expand Down Expand Up @@ -107,7 +113,7 @@ resource "docker_container" "workspace" {
# Hostname makes the shell more user friendly: coder@my-workspace:~$
hostname = lower(data.coder_workspace.me.name)
dns = ["1.1.1.1"]
# Use the docker gateway if the access URL is 127.0.0.1
# Use the docker gateway if the access URL is 127.0.0.1
command = ["sh", "-c", replace(coder_agent.dev.init_script, "127.0.0.1", "host.docker.internal")]
env = ["CODER_AGENT_TOKEN=${coder_agent.dev.token}"]
host {
Expand Down
6 changes: 6 additions & 0 deletions examples/templates/docker/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ resource "coder_agent" "dev" {
curl -fsSL https://code-server.dev/install.sh | sh
code-server --auth none --port 13337
EOF
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
}

resource "coder_app" "code-server" {
Expand Down
6 changes: 6 additions & 0 deletions examples/templates/gcp-linux/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ resource "coder_agent" "dev" {
auth = "google-instance-identity"
arch = "amd64"
os = "linux"
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
}

resource "google_compute_instance" "dev" {
Expand Down
6 changes: 6 additions & 0 deletions examples/templates/gcp-vm-container/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ resource "coder_agent" "dev" {
auth = "google-instance-identity"
arch = "amd64"
os = "linux"
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
}

module "gce-container" {
Expand Down
6 changes: 6 additions & 0 deletions examples/templates/gcp-windows/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ resource "coder_agent" "dev" {
auth = "google-instance-identity"
arch = "amd64"
os = "windows"
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
}

resource "google_compute_instance" "dev" {
Expand Down
18 changes: 18 additions & 0 deletions examples/templates/kubernetes-multi-service/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,34 @@ data "coder_workspace" "me" {}
resource "coder_agent" "go" {
os = "linux"
arch = "amd64"
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
}

resource "coder_agent" "java" {
os = "linux"
arch = "amd64"
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
}

resource "coder_agent" "ubuntu" {
os = "linux"
arch = "amd64"
env = {
GIT_AUTHOR_NAME = "${data.coder_workspace.me.owner}"
GIT_COMMITTER_NAME = "${data.coder_workspace.me.owner}"
GIT_AUTHOR_EMAIL = "${data.coder_workspace.me.owner_email}"
GIT_COMMITTER_EMAIL = "${data.coder_workspace.me.owner_email}"
}
}

resource "kubernetes_pod" "main" {
Expand Down
1 change: 1 addition & 0 deletions provisioner/terraform/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func provisionEnv(start *proto.Provision_Start) ([]string, error) {
"CODER_WORKSPACE_TRANSITION="+strings.ToLower(start.Metadata.WorkspaceTransition.String()),
"CODER_WORKSPACE_NAME="+start.Metadata.WorkspaceName,
"CODER_WORKSPACE_OWNER="+start.Metadata.WorkspaceOwner,
"CODER_WORKSPACE_OWNER_EMAIL="+start.Metadata.WorkspaceOwnerEmail,
"CODER_WORKSPACE_ID="+start.Metadata.WorkspaceId,
"CODER_WORKSPACE_OWNER_ID="+start.Metadata.WorkspaceOwnerId,
)
Expand Down
Loading