Skip to content

Commit

Permalink
chore: fix devcontainer progress
Browse files Browse the repository at this point in the history
- update devcontainer.json to customizations spec
- switch to modern container repository and pin to 1.22-bullseye (same as go.mod)
- install protoc as part of container setup, and its deps https://github.com/ericslandry/grpc/blob/dcc9b228a2189933b0666eeea23852a12225092b/.devcontainer/post-create.sh
  • Loading branch information
budak7273 committed Jan 29, 2025
1 parent f82f620 commit abe294f
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 30 deletions.
6 changes: 3 additions & 3 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
ARG VARIANT=1-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/go:0-${VARIANT}
# Should match go version in go.mod
FROM mcr.microsoft.com/devcontainers/go:1.22-bullseye

ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi

RUN apt-get update && apt-get install redis build-essential libpng-dev -y
RUN apt-get update && apt-get install -y redis build-essential libpng-dev

ENTRYPOINT ["sleep", "infinity"]
25 changes: 25 additions & 0 deletions .devcontainer/create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -ex

# Install protoc (used by go:generate) and add it to path
# Not done in Dockerfile because it seems to lock out writing to some files go needs to write to?
version=25.4
PB_REL="https://github.com/protocolbuffers/protobuf/releases"
curl -LO $PB_REL/download/v$version/protoc-$version-linux-x86_64.zip
unzip protoc-$version-linux-x86_64.zip -d $HOME/.local/
export PATH="$PATH:$HOME/.local/bin"
go install google.golang.org/protobuf/cmd/[email protected]
go install google.golang.org/grpc/cmd/[email protected]
export PATH="$PATH:$(go env GOPATH)/bin"

# Install libwebp (otherwise go:generate tries and fails to build it itself or something)
# https://developers.google.com/speed/webp/docs/precompiled
libwebp_version=1.4.0
libwebp_file="libwebp-$libwebp_version-linux-x86-64.tar.gz"
curl -LO "https://storage.googleapis.com/downloads.webmproject.org/releases/webp/$libwebp_file"
mkdir -p $HOME/libwebp
tar xzvf $libwebp_file -C $HOME/libwebp
export PATH="$PATH:$HOME/libwebp/bin"

# Add as a safe git directory
git config --global --add safe.directory "/workspaces/smr_api"
57 changes: 32 additions & 25 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,47 @@
{
"name": "Go",
"name": "smr-api",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspace",
"workspaceFolder": "/workspaces/smr_api",
"onCreateCommand": "./.devcontainer/create.sh",
"updateContentCommand": "go mod download && go generate -tags tools -x ./...",

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"golang.Go",
"mtxr.sqltools",
"mtxr.sqltools-driver-pg"
],
"settings": {
"go.toolsManagement.checkForUpdates": "local",
"go.useLanguageServer": true,
"go.gopath": "/go",
"go.goroot": "/usr/local/go",
"sqltools.connections": [
{
"name": "Container database",
"driver": "PostgreSQL",
"previewLimit": 50,
"server": "localhost",
"port": 5432,
"database": "postgres",
"username": "postgres",
"password": "REPLACE_ME"
"customizations": {
"vscode": {
"extensions": [
"golang.Go",
"mtxr.sqltools",
"mtxr.sqltools-driver-pg",
"streetsidesoftware.code-spell-checker"
],
"settings": {
"go.toolsManagement.checkForUpdates": "local",
"go.useLanguageServer": true,
"go.gopath": "/go",
"go.goroot": "/usr/local/go",
"sqltools.connections": [
{
"name": "Container database",
"driver": "PostgreSQL",
"previewLimit": 50,
"server": "localhost",
"port": 5432,
"database": "postgres",
"username": "postgres",
"password": "REPLACE_ME"
}
]
}
]
}
},
"forwardPorts": [
5432,
6379,
9000,
9001,
5020,
5020
],
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
}
2 changes: 1 addition & 1 deletion .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
VARIANT: "1-bullseye"
NODE_VERSION: "none"
volumes:
- ..:/workspace:cached
- ..:/workspaces/smr_api:cached
cap_add:
- SYS_PTRACE
network_mode: service:postgres
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ For some simple formatting issues you can use the `--fix` flag, but for more com

```bash
golangci-lint run --fix
```
```
25 changes: 25 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// https://cspell.org/configuration/
{
// Version of the setting file. Always 0.2
"version": "0.2",
// language - current active spelling language
"language": "en",
// words - list of words to be always considered correct
"words": [
"golangci",
"gopath",
"goroot",
"libwebp",
"mtxr",
"Paseto",
"protoc",
"svcacct"
],
// flagWords - list of words to be always considered incorrect
// This is useful for offensive words and common spelling errors.
// cSpell:disable (don't complain about the words we listed here)
"flagWords": [
"hte",
"comunity"
]
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module github.com/satisfactorymodding/smr-api

// when updating, also update .devcontainer/Dockerfile
go 1.22.5

toolchain go1.23.0
Expand Down

0 comments on commit abe294f

Please sign in to comment.