Skip to content

Commit

Permalink
build: Support GitHub Codespace development (#1434)
Browse files Browse the repository at this point in the history
* First pass at sqlc codespace
* Attempt to make CI tests pass in dev containers
* Use default network mode
  • Loading branch information
kyleconroy committed Feb 12, 2022
1 parent 323187f commit 194065e
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 1 deletion.
15 changes: 15 additions & 0 deletions .devcontainer/Dockerfile
@@ -0,0 +1,15 @@
# [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
ARG VARIANT=1.17-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/go:0-${VARIANT}

# [Optional] If your requirements rarely change, uncomment this section to add them to the image.
# COPY requirements.txt /tmp/pip-tmp/
# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
# && rm -rf /tmp/pip-tmp

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>



43 changes: 43 additions & 0 deletions .devcontainer/devcontainer.json
@@ -0,0 +1,43 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/python-3-postgres
// Update the VARIANT arg in docker-compose.yml to pick a Python version
{
"name": "sqlc",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspace",

"runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],

// Set *default* container specific settings.json values on container create.
"settings": {
"sqltools.connections": [{
"name": "Container database",
"driver": "PostgreSQL",
"previewLimit": 50,
"server": "postgresql",
"port": 5432,
"database": "dinotest",
"username": "postgres",
"password": "mysecretpassword"
}],
"go.toolsManagement.checkForUpdates": "local",
"go.useLanguageServer": true,
"go.gopath": "/go",
"go.goroot": "/usr/local/go"
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"golang.Go",
"mtxr.sqltools",
"mtxr.sqltools-driver-pg",
"mtxr.sqltools-driver-mysql"
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [5000, 5432],

// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
46 changes: 46 additions & 0 deletions .devcontainer/docker-compose.yml
@@ -0,0 +1,46 @@
version: '3.8'

services:
app:
build:
context: ..
dockerfile: .devcontainer/Dockerfile
args:
VARIANT: 1.17-bullseye

volumes:
- ..:/workspace:cached

# Overrides default command so things don't shut down after the process ends.
command: sleep infinity

environment:
PG_HOST: postgresql
PG_USER: postgres
PG_DATABASE: dinotest
PG_PASSWORD: mysecretpassword
MYSQL_DATABASE: dinotest
MYSQL_HOST: mysql
MYSQL_ROOT_PASSWORD: mysecretpassword

mysql:
image: "mysql:8"
ports:
- "3306:3306"
restart: unless-stopped
environment:
MYSQL_DATABASE: dinotest
MYSQL_ROOT_PASSWORD: mysecretpassword

postgresql:
image: "postgres:13"
ports:
- "5432:5432"
restart: unless-stopped
environment:
POSTGRES_DB: dinotest
POSTGRES_PASSWORD: mysecretpassword
POSTGRES_USER: postgres

# Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)
10 changes: 9 additions & 1 deletion Makefile
@@ -1,4 +1,4 @@
.PHONY: build test test-examples regen start psql mysqlsh
.PHONY: build build-endtoend test test-ci test-examples test-endtoend regen start psql mysqlsh

build:
go build ./...
Expand All @@ -9,6 +9,14 @@ test:
test-examples:
go test --tags=examples ./...

build-endtoend:
cd ./internal/endtoend/testdata && go build ./...

test-endtoend:
cd ./internal/endtoend/testdata && go test ./...

test-ci: test-examples build-endtoend test-endtoend

regen: sqlc-dev
go run ./scripts/regenerate/

Expand Down

0 comments on commit 194065e

Please sign in to comment.