Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
29b1bba
feat: added firebase module
xytis May 23, 2024
6a88123
chore: bump default container version
xytis Jan 30, 2025
4105b0a
fix: rewrote the module based on comments
xytis Jan 31, 2025
cc2bfa4
fix: another pass at comments
xytis Feb 2, 2025
7c24032
fix: ports are uint
xytis Feb 3, 2025
bc68bb3
Merge branch 'main' into u-health/main
mdelapenya Apr 14, 2025
bc33438
chore: bump testcontainers-go to latest
mdelapenya Apr 14, 2025
1a72008
chore: move to testdata
mdelapenya Apr 14, 2025
c2b8e2b
chore: use custom error when root is needed
mdelapenya Apr 14, 2025
ba0bdc0
fix: handle error in test
mdelapenya Apr 14, 2025
80298e5
chore: use new functional options
mdelapenya Apr 14, 2025
4e271db
fix: no need to pass labels, as they are added in the core
mdelapenya Apr 14, 2025
34409eb
chore: proper error message
mdelapenya Apr 14, 2025
fb2c0aa
chore: move options to its file
mdelapenya Apr 14, 2025
88cb16d
chore: simplify concat
mdelapenya Apr 14, 2025
aa4c29c
chore: add whilelines to separate concerns
mdelapenya Apr 14, 2025
458cc7c
docs: document the new options
mdelapenya Apr 14, 2025
ae27c74
merge: pull request #1 from mdelapenya/firebase-module
xytis Apr 14, 2025
ae49941
fix: lint pass
xytis Apr 23, 2025
cff37d9
fix: another lint pass
xytis Apr 23, 2025
9fe4988
Update modules/firebase/ports.go
xytis Apr 25, 2025
3ed1839
Update modules/firebase/ports.go
xytis Apr 25, 2025
d578817
Merge branch 'main' into main
xytis Apr 25, 2025
72c1f45
chore: reverted example test to failing state, so we could fix the ro…
xytis Apr 25, 2025
fd6035e
Update modules/firebase/ports.go
xytis Apr 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
matrix:
go-version: [1.22.x, 1.x]
platform: [ubuntu-latest]
module: [artemis, azurite, cassandra, chroma, clickhouse, cockroachdb, compose, consul, couchbase, databend, dolt, dynamodb, elasticsearch, etcd, gcloud, grafana-lgtm, inbucket, influxdb, k3s, k6, kafka, localstack, mariadb, meilisearch, milvus, minio, mockserver, mongodb, mssql, mysql, nats, neo4j, ollama, openfga, openldap, opensearch, postgres, pulsar, qdrant, rabbitmq, redis, redpanda, registry, surrealdb, valkey, vault, vearch, weaviate, yugabytedb]
module: [artemis, azurite, cassandra, chroma, clickhouse, cockroachdb, compose, consul, couchbase, databend, dolt, dynamodb, elasticsearch, etcd, firebase, gcloud, grafana-lgtm, inbucket, influxdb, k3s, k6, kafka, localstack, mariadb, meilisearch, milvus, minio, mockserver, mongodb, mssql, mysql, nats, neo4j, ollama, openfga, openldap, opensearch, postgres, pulsar, qdrant, rabbitmq, redis, redpanda, registry, surrealdb, valkey, vault, vearch, weaviate, yugabytedb]
uses: ./.github/workflows/ci-test-go.yml
with:
go-version: ${{ matrix.go-version }}
Expand Down
6 changes: 5 additions & 1 deletion .vscode/.testcontainers-go.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
"name": "module / etcd",
"path": "../modules/etcd"
},
{
"name": "module / firebase",
"path": "../modules/firebase"
},
{
"name": "module / gcloud",
"path": "../modules/gcloud"
Expand Down Expand Up @@ -214,4 +218,4 @@
"path": "../modulegen"
}
]
}
}
55 changes: 55 additions & 0 deletions docs/modules/firebase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Firebase

Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

## Introduction

The Testcontainers module for Firebase.

## Adding this module to your project dependencies

Please run the following command to add the Firebase module to your Go dependencies:

```
go get github.com/testcontainers/testcontainers-go/modules/firebase
```

## Usage example

<!--codeinclude-->
[Creating a Firebase container](../../modules/firebase/examples_test.go) inside_block:ExampleRun
<!--/codeinclude-->

## Module Reference

### Run function

- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>

!!!info
The `RunContainer(ctx, opts...)` function is deprecated and will be removed in the next major release of _Testcontainers for Go_.

The Firebase module exposes one entrypoint function to create the Firebase container, and this function receives three parameters:

```golang
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*FirebaseContainer, error)
```

- `context.Context`, the Go context.
- `string`, the Docker image to use.
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options.

### Container Options

When starting the Firebase container, you can pass options in a variadic way to configure it.

#### Image

If you need to set a different Firebase Docker image, you can set a valid Docker image as the second argument in the `Run` function.
E.g. `Run(context.Background(), "ghcr.io/u-health/docker-firebase-emulator:13.29.2")`.

{% include "../features/common_functional_options.md" %}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docsd: we need to add here all the functional options for the module.

Copy link
Member

@mdelapenya mdelapenya Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xytis let's not forget adding the WithData option here 🙏

### Container Methods

The Firebase container exposes the following methods:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docs: we probably need to append here the new methods the container expose

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xytis let's not forget adding here ConnectionString 🙏

1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ nav:
- modules/dynamodb.md
- modules/elasticsearch.md
- modules/etcd.md
- modules/firebase.md
- modules/gcloud.md
- modules/grafana-lgtm.md
- modules/inbucket.md
Expand Down
5 changes: 5 additions & 0 deletions modules/firebase/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include ../../commons-test.mk

.PHONY: test
test:
$(MAKE) test-firebase
87 changes: 87 additions & 0 deletions modules/firebase/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package firebase

// Based on https://github.com/firebase/firebase-tools/blob/master/src/firebaseConfig.ts

type emulatorsConfig struct {
SingleProjectMode bool `json:"singleProjectMode,omitempty"`

Auth struct {
Host string `json:"host,omitempty"`
Port uint16 `json:"port,omitempty"`
} `json:"auth,omitempty"`

Database struct {
Host string `json:"host,omitempty"`
Port uint16 `json:"port,omitempty"`
} `json:"database,omitempty"`

Firestore struct {
Host string `json:"host,omitempty"`
Port uint16 `json:"port,omitempty"`
WebsocketPort uint16 `json:"websocketPort,omitempty"`
} `json:"firestore,omitempty"`

Functions struct {
Host string `json:"host,omitempty"`
Port uint16 `json:"port,omitempty"`
} `json:"functions,omitempty"`

Hosting struct {
Host string `json:"host,omitempty"`
Port uint16 `json:"port,omitempty"`
} `json:"hosting,omitempty"`

AppHosting struct {
Host string `json:"host,omitempty"`
Port uint16 `json:"port,omitempty"`
StartCommand string `json:"startCommand,omitempty"`
RootDirectory string `json:"rootDirectory,omitempty"`
} `json:"apphosting,omitempty"`

PubSub struct {
Host string `json:"host,omitempty"`
Port uint16 `json:"port,omitempty"`
} `json:"pubsub,omitempty"`

Storage struct {
Host string `json:"host,omitempty"`
Port uint16 `json:"port,omitempty"`
} `json:"storage,omitempty"`

Logging struct {
Host string `json:"host,omitempty"`
Port uint16 `json:"port,omitempty"`
} `json:"logging,omitempty"`

Hub struct {
Host string `json:"host,omitempty"`
Port uint16 `json:"port,omitempty"`
} `json:"hub,omitempty"`

UI struct {
Enabled bool `json:"enabled,omitempty"`
Host string `json:"host,omitempty"`
Port uint16 `json:"port,omitempty"`
} `json:"ui,omitempty"`

EventArc struct {
Host string `json:"host,omitempty"`
Port uint16 `json:"port,omitempty"`
} `json:"eventarc,omitempty"`

DataConnect struct {
Host string `json:"host,omitempty"`
Port uint16 `json:"port,omitempty"`
PostgresHost string `json:"postgresHost,omitempty"`
PostgresPort uint16 `json:"postgresPort,omitempty"`
DataDir string `json:"dataDir,omitempty"`
} `json:"dataconnect,omitempty"`

Tasks struct {
Host string `json:"host,omitempty"`
Port uint16 `json:"port,omitempty"`
} `json:"tasks,omitempty"`
}
type partialFirebaseConfig struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add a blank line between types, suspect it will fail linting without.

Emulators emulatorsConfig `json:"emulators,omitempty"`
}
40 changes: 40 additions & 0 deletions modules/firebase/examples_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package firebase_test

import (
"context"
"fmt"
"log"
"path/filepath"

"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/modules/firebase"
)

func ExampleRun() {
ctx := context.Background()

firebaseContainer, err := firebase.Run(ctx, "ghcr.io/u-health/docker-firebase-emulator:13.29.2",
firebase.WithRoot(filepath.Join(".", "firebase")),
firebase.WithCache(),
)
defer func() {
if err := testcontainers.TerminateContainer(firebaseContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
if err != nil {
log.Printf("failed to start container: %s", err)
return
}

state, err := firebaseContainer.State(ctx)
if err != nil {
log.Printf("failed to get container state: %s", err)
return
}

fmt.Println(state.Running)

// Output:
// true
}
5 changes: 5 additions & 0 deletions modules/firebase/failure/.firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "test"
}
}
39 changes: 39 additions & 0 deletions modules/firebase/failure/firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"emulators": {
"ui": {
"//": "UI will only partially work in the container. Because ports get mangled, some of the features will be broken. A solution is to run UI externally and provide the mangled ports as inputs.",
"enabled": true,
"port": 4000,
"host": "0.0.0.0"
},
"hub": {
"port": 4400,
"host": "0.0.0.0"
},
"logging": {
"port": 4600,
"host": "0.0.0.0"
},
"firestore": {
"port": 8080,
"host": "0.0.0.0",
"websocketPort": 8081
},
"auth": {
"port": 9099,
"host": "0.0.0.0"
},
"storage": {
"port": 9199,
"host": "0.0.0.0"
},
"singleProjectMode": true
},
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"storage": {
"rules": "storage.rules"
}
}
4 changes: 4 additions & 0 deletions modules/firebase/failure/firestore.indexes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"indexes": [],
"fieldOverrides": []
}
9 changes: 9 additions & 0 deletions modules/firebase/failure/firestore.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
}
}

8 changes: 8 additions & 0 deletions modules/firebase/failure/storage.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if true;
}
}
}
Loading