Skip to content

Commit d32247d

Browse files
committed
Merge branch 'main' into 3321-template-space-b
2 parents a837fae + d64c73d commit d32247d

File tree

5 files changed

+64
-12
lines changed

5 files changed

+64
-12
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,6 @@ site/out/
4949
**/*.swp
5050
.coderv2/*
5151
**/__debug_bin
52+
53+
# direnv
54+
.envrc

coderd/database/gen/dump/main.go

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ import (
88
"os/exec"
99
"path/filepath"
1010
"runtime"
11+
"strconv"
12+
"strings"
1113

1214
"github.com/coder/coder/coderd/database/migrations"
1315
"github.com/coder/coder/coderd/database/postgres"
1416
)
1517

18+
const minimumPostgreSQLVersion = 13
19+
1620
func main() {
1721
connection, closeFn, err := postgres.Open()
1822
if err != nil {
@@ -30,12 +34,23 @@ func main() {
3034
panic(err)
3135
}
3236

33-
cmd := exec.Command(
34-
"docker",
35-
"run",
36-
"--rm",
37-
"--network=host",
38-
"postgres:13",
37+
hasPGDump := false
38+
if _, err = exec.LookPath("pg_dump"); err == nil {
39+
out, err := exec.Command("pg_dump", "--version").Output()
40+
if err == nil {
41+
// Parse output:
42+
// pg_dump (PostgreSQL) 14.5 (Ubuntu 14.5-0ubuntu0.22.04.1)
43+
parts := strings.Split(string(out), " ")
44+
if len(parts) > 2 {
45+
version, err := strconv.Atoi(strings.Split(parts[2], ".")[0])
46+
if err == nil && version >= minimumPostgreSQLVersion {
47+
hasPGDump = true
48+
}
49+
}
50+
}
51+
}
52+
53+
cmdArgs := []string{
3954
"pg_dump",
4055
"--schema-only",
4156
connection,
@@ -45,8 +60,18 @@ func main() {
4560
// We never want to manually generate
4661
// queries executing against this table.
4762
"--exclude-table=schema_migrations",
48-
)
63+
}
4964

65+
if !hasPGDump {
66+
cmdArgs = append([]string{
67+
"docker",
68+
"run",
69+
"--rm",
70+
"--network=host",
71+
fmt.Sprintf("postgres:%d", minimumPostgreSQLVersion),
72+
}, cmdArgs...)
73+
}
74+
cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...) //#nosec
5075
cmd.Env = append(os.Environ(), []string{
5176
"PGTZ=UTC",
5277
"PGCLIENTENCODING=UTF8",

coderd/database/generate.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ SCRIPT_DIR=$(dirname "${BASH_SOURCE[0]}")
1313
(
1414
cd "$SCRIPT_DIR"
1515

16-
# Dump the updated schema.
17-
go run gen/dump/main.go
16+
echo generate 1>&2
17+
18+
# Dump the updated schema (use make to utilize caching).
19+
make -C ../.. --no-print-directory coderd/database/dump.sql
1820
# The logic below depends on the exact version being correct :(
1921
go run github.com/kyleconroy/sqlc/cmd/sqlc@v1.13.0 generate
2022

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
11
FROM ubuntu
22

3-
RUN apt-get update && apt-get install -y curl wget git vim golang
3+
RUN apt-get update \
4+
&& apt-get install -y \
5+
curl \
6+
git \
7+
golang \
8+
sudo \
9+
vim \
10+
wget \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
ARG USER=coder
14+
RUN useradd --groups sudo --no-create-home ${USER} \
15+
&& echo "${USER} ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/${USER} \
16+
&& chmod 0440 /etc/sudoers.d/${USER}
17+
USER ${USER}
18+
WORKDIR /home/${USER}

examples/templates/docker/main.tf

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ terraform {
1111
}
1212
}
1313

14+
locals {
15+
username = data.coder_workspace.me.owner
16+
}
17+
1418
data "coder_provisioner" "me" {
1519
}
1620

@@ -46,7 +50,7 @@ resource "coder_app" "code-server" {
4650
agent_id = coder_agent.main.id
4751
slug = "code-server"
4852
display_name = "code-server"
49-
url = "http://localhost:13337/?folder=/home/coder"
53+
url = "http://localhost:13337/?folder=/home/${local.username}"
5054
icon = "/icon/code.svg"
5155
subdomain = false
5256
share = "owner"
@@ -91,6 +95,9 @@ resource "docker_image" "main" {
9195
name = "coder-${data.coder_workspace.me.id}"
9296
build {
9397
path = "./build"
98+
build_arg = {
99+
USER = local.username
100+
}
94101
}
95102
triggers = {
96103
dir_sha1 = sha1(join("", [for f in fileset(path.module, "build/*") : filesha1(f)]))
@@ -112,7 +119,7 @@ resource "docker_container" "workspace" {
112119
ip = "host-gateway"
113120
}
114121
volumes {
115-
container_path = "/home/coder/"
122+
container_path = "/home/${local.username}"
116123
volume_name = docker_volume.home_volume.name
117124
read_only = false
118125
}

0 commit comments

Comments
 (0)