Skip to content

Commit 194065e

Browse files
authored
build: Support GitHub Codespace development (#1434)
* First pass at sqlc codespace * Attempt to make CI tests pass in dev containers * Use default network mode
1 parent 323187f commit 194065e

File tree

4 files changed

+113
-1
lines changed

4 files changed

+113
-1
lines changed

.devcontainer/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# [Choice] Go version (use -bullseye variants on local arm64/Apple Silicon): 1, 1.16, 1.17, 1-bullseye, 1.16-bullseye, 1.17-bullseye, 1-buster, 1.16-buster, 1.17-buster
2+
ARG VARIANT=1.17-bullseye
3+
FROM mcr.microsoft.com/vscode/devcontainers/go:0-${VARIANT}
4+
5+
# [Optional] If your requirements rarely change, uncomment this section to add them to the image.
6+
# COPY requirements.txt /tmp/pip-tmp/
7+
# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
8+
# && rm -rf /tmp/pip-tmp
9+
10+
# [Optional] Uncomment this section to install additional OS packages.
11+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
12+
# && apt-get -y install --no-install-recommends <your-package-list-here>
13+
14+
15+

.devcontainer/devcontainer.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/python-3-postgres
3+
// Update the VARIANT arg in docker-compose.yml to pick a Python version
4+
{
5+
"name": "sqlc",
6+
"dockerComposeFile": "docker-compose.yml",
7+
"service": "app",
8+
"workspaceFolder": "/workspace",
9+
10+
"runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],
11+
12+
// Set *default* container specific settings.json values on container create.
13+
"settings": {
14+
"sqltools.connections": [{
15+
"name": "Container database",
16+
"driver": "PostgreSQL",
17+
"previewLimit": 50,
18+
"server": "postgresql",
19+
"port": 5432,
20+
"database": "dinotest",
21+
"username": "postgres",
22+
"password": "mysecretpassword"
23+
}],
24+
"go.toolsManagement.checkForUpdates": "local",
25+
"go.useLanguageServer": true,
26+
"go.gopath": "/go",
27+
"go.goroot": "/usr/local/go"
28+
},
29+
30+
// Add the IDs of extensions you want installed when the container is created.
31+
"extensions": [
32+
"golang.Go",
33+
"mtxr.sqltools",
34+
"mtxr.sqltools-driver-pg",
35+
"mtxr.sqltools-driver-mysql"
36+
],
37+
38+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
39+
// "forwardPorts": [5000, 5432],
40+
41+
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
42+
"remoteUser": "vscode"
43+
}

.devcontainer/docker-compose.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
version: '3.8'
2+
3+
services:
4+
app:
5+
build:
6+
context: ..
7+
dockerfile: .devcontainer/Dockerfile
8+
args:
9+
VARIANT: 1.17-bullseye
10+
11+
volumes:
12+
- ..:/workspace:cached
13+
14+
# Overrides default command so things don't shut down after the process ends.
15+
command: sleep infinity
16+
17+
environment:
18+
PG_HOST: postgresql
19+
PG_USER: postgres
20+
PG_DATABASE: dinotest
21+
PG_PASSWORD: mysecretpassword
22+
MYSQL_DATABASE: dinotest
23+
MYSQL_HOST: mysql
24+
MYSQL_ROOT_PASSWORD: mysecretpassword
25+
26+
mysql:
27+
image: "mysql:8"
28+
ports:
29+
- "3306:3306"
30+
restart: unless-stopped
31+
environment:
32+
MYSQL_DATABASE: dinotest
33+
MYSQL_ROOT_PASSWORD: mysecretpassword
34+
35+
postgresql:
36+
image: "postgres:13"
37+
ports:
38+
- "5432:5432"
39+
restart: unless-stopped
40+
environment:
41+
POSTGRES_DB: dinotest
42+
POSTGRES_PASSWORD: mysecretpassword
43+
POSTGRES_USER: postgres
44+
45+
# Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
46+
# (Adding the "ports" property to this file will not forward from a Codespace.)

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: build test test-examples regen start psql mysqlsh
1+
.PHONY: build build-endtoend test test-ci test-examples test-endtoend regen start psql mysqlsh
22

33
build:
44
go build ./...
@@ -9,6 +9,14 @@ test:
99
test-examples:
1010
go test --tags=examples ./...
1111

12+
build-endtoend:
13+
cd ./internal/endtoend/testdata && go build ./...
14+
15+
test-endtoend:
16+
cd ./internal/endtoend/testdata && go test ./...
17+
18+
test-ci: test-examples build-endtoend test-endtoend
19+
1220
regen: sqlc-dev
1321
go run ./scripts/regenerate/
1422

0 commit comments

Comments
 (0)