Skip to content

Commit 834c88f

Browse files
authored
Merge pull request #945 from nyaruka/devcontainer
Add devcontainer configuration
2 parents 60d3bfc + 840eb7a commit 834c88f

File tree

11 files changed

+53
-38
lines changed

11 files changed

+53
-38
lines changed

.devcontainer/devcontainer.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "Courier",
3+
"image": "mcr.microsoft.com/devcontainers/go:dev-1.25-trixie",
4+
"features": {},
5+
"runArgs": [
6+
"--name=dev-courier",
7+
"--network=textit_default"
8+
],
9+
"customizations": {
10+
"vscode": {
11+
"extensions": [
12+
"netcorext.uuid-generator"
13+
],
14+
"settings": {
15+
"terminal.integrated.defaultProfile.linux": "zsh",
16+
"editor.formatOnSave": true,
17+
"editor.rulers": [
18+
120
19+
]
20+
}
21+
}
22+
}
23+
}

.github/workflows/ci.yml

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
name: CI
22
on: [push, pull_request]
3-
env:
4-
go-version: "1.25.x"
53
jobs:
64
test:
75
name: Test
86
runs-on: ubuntu-latest
7+
container:
8+
image: golang:1.25-trixie
99

1010
services:
1111
valkey:
@@ -21,23 +21,17 @@ jobs:
2121
ports:
2222
- 5432:5432
2323
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
24+
localstack:
25+
image: localstack/localstack:latest
26+
env:
27+
SERVICES: s3,dynamodb,cloudwatch
28+
ports:
29+
- 4566:4566
2430

2531
steps:
2632
- name: Checkout code
2733
uses: actions/checkout@v4
2834

29-
- name: Install Go
30-
uses: actions/setup-go@v5
31-
with:
32-
go-version: ${{ env.go-version }}
33-
34-
- name: Start LocalStack
35-
uses: LocalStack/[email protected]
36-
with:
37-
image-tag: 'latest'
38-
configuration: |
39-
SERVICES=s3,dynamodb,cloudwatch
40-
4135
- name: Run tests
4236
run: go test -p=1 -coverprofile=coverage.text -covermode=atomic ./...
4337

@@ -53,17 +47,15 @@ jobs:
5347
needs: [test]
5448
if: startsWith(github.ref, 'refs/tags/')
5549
runs-on: ubuntu-latest
50+
container:
51+
image: golang:1.25-trixie
52+
5653
steps:
5754
- name: Checkout code
5855
uses: actions/checkout@v4
5956
with:
6057
fetch-depth: 0
6158

62-
- name: Install Go
63-
uses: actions/setup-go@v5
64-
with:
65-
go-version: ${{ env.go-version }}
66-
6759
- name: Publish release
6860
uses: goreleaser/goreleaser-action@v6
6961
if: ${{ !contains(github.ref, '-') }}

backends/rapidpro/backend_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ func (ts *BackendTestSuite) TestSaveAttachment() {
10531053

10541054
newURL, err := ts.b.SaveAttachment(ctx, knChannel, "image/jpeg", testJPG, "jpg")
10551055
ts.NoError(err)
1056-
ts.Equal("http://localhost:4566/test-attachments/attachments/1/c00e/5d67/c00e5d67-c275-4389-aded-7d8b151cbd5b.jpg", newURL)
1056+
ts.Equal("http://localstack:4566/test-attachments/attachments/1/c00e/5d67/c00e5d67-c275-4389-aded-7d8b151cbd5b.jpg", newURL)
10571057
}
10581058

10591059
func (ts *BackendTestSuite) TestWriteMsg() {
@@ -1175,7 +1175,7 @@ func (ts *BackendTestSuite) TestWriteMsgWithAttachments() {
11751175
// should have actually fetched and saved it to storage, with the correct content type
11761176
err = ts.b.WriteMsg(ctx, msg2, clog)
11771177
ts.NoError(err)
1178-
ts.Equal([]string{"image/jpeg:http://localhost:4566/test-attachments/attachments/1/37c5/fddb/37c5fddb-8512-4a80-8c21-38b6e22ef940.jpg"}, msg2.Attachments())
1178+
ts.Equal([]string{"image/jpeg:http://localstack:4566/test-attachments/attachments/1/37c5/fddb/37c5fddb-8512-4a80-8c21-38b6e22ef940.jpg"}, msg2.Attachments())
11791179

11801180
// try an invalid embedded attachment
11811181
msg3 := ts.b.NewIncomingMsg(ctx, knChannel, urn, "invalid embedded attachment data", "", clog).(*MsgIn)

handlers/jiochat/handler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ func newServer(backend courier.Backend) courier.Server {
262262
logger := slog.Default()
263263
log.SetOutput(io.Discard)
264264
cfg := runtime.NewDefaultConfig()
265-
cfg.DB = "postgres://courier_test:temba@localhost:5432/courier_test?sslmode=disable"
266-
cfg.Valkey = "valkey://localhost:6379/0"
265+
cfg.DB = "postgres://courier_test:temba@postgres:5432/courier_test?sslmode=disable"
266+
cfg.Valkey = "valkey://valkey:6379/0"
267267
return courier.NewServerWithLogger(cfg, backend, logger)
268268
}
269269

handlers/wechat/handler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ func newServer(backend courier.Backend) courier.Server {
215215
logger := slog.Default()
216216
log.SetOutput(io.Discard)
217217
cfg := runtime.NewDefaultConfig()
218-
cfg.DB = "postgres://courier_test:temba@localhost:5432/courier_test?sslmode=disable"
219-
cfg.Valkey = "valkey://localhost:6379/0"
218+
cfg.DB = "postgres://courier_test:temba@postgres:5432/courier_test?sslmode=disable"
219+
cfg.Valkey = "valkey://valkey:6379/0"
220220
return courier.NewServerWithLogger(cfg, backend, logger)
221221
}
222222

runtime/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ type Config struct {
6666
func NewDefaultConfig() *Config {
6767
hostname, _ := os.Hostname()
6868
return &Config{
69-
DB: "postgres://temba:temba@localhost/temba?sslmode=disable",
70-
Valkey: "valkey://localhost:6379/15",
69+
DB: "postgres://temba:temba@postgres/temba?sslmode=disable",
70+
Valkey: "valkey://valkey:6379/15",
7171
SpoolDir: "/var/spool/courier",
7272

7373
Domain: "localhost",

runtime/config_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ var invalidConfigTestCases = []struct {
1111
config *runtime.Config
1212
expectedError string
1313
}{
14-
{config: &runtime.Config{DB: ":foo", Valkey: "valkey:localhost/23"}, expectedError: "Field validation for 'DB' failed on the 'url' tag"},
15-
{config: &runtime.Config{DB: "mysql:test", Valkey: "valkey:localhost/23"}, expectedError: "Field validation for 'DB' failed on the 'startswith' tag"},
16-
{config: &runtime.Config{DB: "postgres://courier:courier@localhost:5432/courier", Valkey: ":foo"}, expectedError: "Field validation for 'Valkey' failed on the 'url' tag"},
14+
{config: &runtime.Config{DB: ":foo", Valkey: "valkey:valkey/23"}, expectedError: "Field validation for 'DB' failed on the 'url' tag"},
15+
{config: &runtime.Config{DB: "mysql:test", Valkey: "valkey:valkey/23"}, expectedError: "Field validation for 'DB' failed on the 'startswith' tag"},
16+
{config: &runtime.Config{DB: "postgres://courier:courier@postgres:5432/courier", Valkey: ":foo"}, expectedError: "Field validation for 'Valkey' failed on the 'url' tag"},
1717
}
1818

1919
func TestConfigValidate(t *testing.T) {

server_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424

2525
func testConfig() *runtime.Config {
2626
cfg := runtime.NewDefaultConfig()
27-
cfg.DB = "postgres://courier_test:temba@localhost:5432/courier_test?sslmode=disable"
28-
cfg.Valkey = "valkey://localhost:6379/0"
27+
cfg.DB = "postgres://courier_test:temba@postgres:5432/courier_test?sslmode=disable"
28+
cfg.Valkey = "valkey://valkey:6379/0"
2929
cfg.Port = 8081
3030
return cfg
3131
}

test/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func NewMockBackend() *MockBackend {
5858
MaxIdle: 2, // only keep up to 2 idle
5959
IdleTimeout: 240 * time.Second, // how long to wait before reaping a connection
6060
Dial: func() (redis.Conn, error) {
61-
conn, err := redis.Dial("tcp", "localhost:6379")
61+
conn, err := redis.Dial("tcp", "valkey:6379")
6262
if err != nil {
6363
return nil, err
6464
}

testsuite/runtime.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ const (
2020

2121
func Runtime(t *testing.T) (context.Context, *runtime.Runtime) {
2222
cfg := runtime.NewDefaultConfig()
23-
cfg.DB = "postgres://courier_test:temba@localhost:5432/courier_test?sslmode=disable"
24-
cfg.Valkey = "valkey://localhost:6379/0"
23+
cfg.DB = "postgres://courier_test:temba@postgres:5432/courier_test?sslmode=disable"
24+
cfg.Valkey = "valkey://valkey:6379/0"
2525
cfg.MediaDomain = "nyaruka.s3.com"
2626

2727
// configure S3 to use a localstack instance
2828
cfg.AWSAccessKeyID = "root"
2929
cfg.AWSSecretAccessKey = "tembatemba"
30-
cfg.S3Endpoint = "http://localhost:4566"
30+
cfg.S3Endpoint = "http://localstack:4566"
3131
cfg.S3AttachmentsBucket = "test-attachments"
3232
cfg.S3PathStyle = true
33-
cfg.DynamoEndpoint = "http://localhost:4566"
33+
cfg.DynamoEndpoint = "http://localstack:4566"
3434
cfg.DynamoTablePrefix = "Test"
3535
cfg.SpoolDir = absPath("./_test_spool")
3636

0 commit comments

Comments
 (0)