[PR #659] [MERGED] Add "internal config update" endpoint to set externalUrl property after the fake server start #803

Closed
opened 2026-03-03 12:31:42 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/fsouza/fake-gcs-server/pull/659
Author: @sergseven
Created: 1/25/2022
Status: Merged
Merged: 1/28/2022
Merged by: @fsouza

Base: mainHead: upload-content-fix


📝 Commits (10+)

  • 8406bd2 modify image name to sergseven
  • 7364662 return PublicURL() as location response header
  • 5b2e005 add .tool-versions
  • 48415ad revert 'return PublicURL() as location response header'
  • cb138c0 add internal update server config endpoint
  • 713f68d revert wrong test case
  • 8d70a63 remove if body != nil since always non-nil
  • ee92c00 fix examples to set a real external url
  • eb1fce8 fix test case name
  • 26586c0 remove redundant return

📊 Changes

13 files changed (+655 additions, -1 deletions)

View changed files

📝 .github/workflows/main.yml (+3 -0)
📝 README.md (+1 -1)
ci/run-java-example.sh (+12 -0)
📝 examples/go/main.go (+21 -0)
examples/java/.gitignore (+2 -0)
examples/java/.mvn/wrapper/maven-wrapper.properties (+2 -0)
examples/java/README.md (+105 -0)
examples/java/mvnw (+310 -0)
examples/java/pom.xml (+71 -0)
examples/java/src/test/java/com/fsouza/fakegcsserver/java/examples/FakeGcsServerTest.java (+47 -0)
fakestorage/config.go (+26 -0)
📝 fakestorage/server.go (+5 -0)
📝 fakestorage/server_test.go (+50 -0)

📄 Description

This change is dedicated to the problem with resumable uploads where it's necessary for fake-gcs-server to respond with "content" HTTP header with external URL which has to be accessible from storage client uses this fake server.

The suggested solution is to specify "external-url" at the endpoint command with the URL this fake server is accessible.
It works for a regular case for local development, but it's getting more difficult when server is hosted on a container, (particularly using https://www.testcontainers.org/) so external URL is different than "public URL" fake-gcs-server" exposes.

Example:

@Testcontainers
class FakeGcsServerTest {
    // random port
    static int fakeGcsContainerPort = 4321;

    @Container
    static final GenericContainer<?> fakeGcs = new FixedHostPortGenericContainer<>("fsouza/fake-gcs-server")
        .withExposedPorts(4443)
        .withFixedExposedPort(4443, fakeGcsContainerIp)
        .withCreateContainerCmdModifier(cmd -> cmd.withEntrypoint(
            "/bin/fake-gcs-server",
            "-scheme", "http",
            // at this point there is no way to get a container IP
            // before the container started, so setting "localhost"
            "-external-url", "http://localhost:" + fakeGcsContainerPort
                                                                                                                 
        ));

    @Test
    void testWithFakeGcs() {
             var storageService = StorageOptions.newBuilder()
            .setHost("http://localhost:" + fakeGcs.getFirstMappedPort())
            .setProjectId("test-project")
            .setCredentials(NoCredentials.getInstance())
            .build()
            .getService();

            WriteChannel channel = storageService.writer(BlobInfo.newBuilder("sample-bucket2", "some_file2.txt").build());
            channel.write(ByteBuffer.wrap("line1\n".getBytes()));
            channel.write(ByteBuffer.wrap("line2\n".getBytes()));
            channel.close(); // <- ERROR on CI environment expected!
    }

The solution proposed is to modify fake-gcs-server configuration AFTER the container is eventually started and container IP is known:

String fakeGcsExternalUrl = "http://" + fakeGcs.getContainerIpAddress() + ":" + fakeGcs.getFirstMappedPort();
updateExternalUrlWithContainerUrl(fakeGcsExternalUrl);

See the full example at https://github.com/sergseven/fake-gcs-server/blob/upload-content-fix/examples/java/README.md#resumable-upload-operations-and-containerised-fake-gcs-server


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/fsouza/fake-gcs-server/pull/659 **Author:** [@sergseven](https://github.com/sergseven) **Created:** 1/25/2022 **Status:** ✅ Merged **Merged:** 1/28/2022 **Merged by:** [@fsouza](https://github.com/fsouza) **Base:** `main` ← **Head:** `upload-content-fix` --- ### 📝 Commits (10+) - [`8406bd2`](https://github.com/fsouza/fake-gcs-server/commit/8406bd28cdcd9ce40ba61ae32b403f47b3b24557) modify image name to sergseven - [`7364662`](https://github.com/fsouza/fake-gcs-server/commit/7364662391c385a566bd4a0a7aacde711199a3bc) return PublicURL() as location response header - [`5b2e005`](https://github.com/fsouza/fake-gcs-server/commit/5b2e005aa4bf02b73aea8d830a59648c438495e1) add .tool-versions - [`48415ad`](https://github.com/fsouza/fake-gcs-server/commit/48415ad3b74cb0919e1aeba6b00045fd4f8216b5) revert 'return PublicURL() as location response header' - [`cb138c0`](https://github.com/fsouza/fake-gcs-server/commit/cb138c0280b624f85b41f00562d93587458f9957) add internal update server config endpoint - [`713f68d`](https://github.com/fsouza/fake-gcs-server/commit/713f68dd0e75bd3458d12a309211e62fa7b112ff) revert wrong test case - [`8d70a63`](https://github.com/fsouza/fake-gcs-server/commit/8d70a63744554407cf6251b0bb7824cf18d9fa94) remove if body != nil since always non-nil - [`ee92c00`](https://github.com/fsouza/fake-gcs-server/commit/ee92c00bc54c35f36953a10ede3177ae1c514763) fix examples to set a real external url - [`eb1fce8`](https://github.com/fsouza/fake-gcs-server/commit/eb1fce8c781ac5db662a346aa7ccd89d2a6aa5b4) fix test case name - [`26586c0`](https://github.com/fsouza/fake-gcs-server/commit/26586c0101896a4706809b401758fc46ca28d92f) remove redundant return ### 📊 Changes **13 files changed** (+655 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/main.yml` (+3 -0) 📝 `README.md` (+1 -1) ➕ `ci/run-java-example.sh` (+12 -0) 📝 `examples/go/main.go` (+21 -0) ➕ `examples/java/.gitignore` (+2 -0) ➕ `examples/java/.mvn/wrapper/maven-wrapper.properties` (+2 -0) ➕ `examples/java/README.md` (+105 -0) ➕ `examples/java/mvnw` (+310 -0) ➕ `examples/java/pom.xml` (+71 -0) ➕ `examples/java/src/test/java/com/fsouza/fakegcsserver/java/examples/FakeGcsServerTest.java` (+47 -0) ➕ `fakestorage/config.go` (+26 -0) 📝 `fakestorage/server.go` (+5 -0) 📝 `fakestorage/server_test.go` (+50 -0) </details> ### 📄 Description This change is dedicated to the problem with resumable uploads where it's necessary for fake-gcs-server to respond with "content" HTTP header with external URL which has to be accessible from storage client uses this fake server. The suggested solution is to specify "external-url" at the endpoint command with the URL this fake server is accessible. It works for a regular case for local development, but it's getting more difficult when server is hosted on a container, (particularly using https://www.testcontainers.org/) so external URL is different than "public URL" fake-gcs-server" exposes. Example: ``` @Testcontainers class FakeGcsServerTest { // random port static int fakeGcsContainerPort = 4321; @Container static final GenericContainer<?> fakeGcs = new FixedHostPortGenericContainer<>("fsouza/fake-gcs-server") .withExposedPorts(4443) .withFixedExposedPort(4443, fakeGcsContainerIp) .withCreateContainerCmdModifier(cmd -> cmd.withEntrypoint( "/bin/fake-gcs-server", "-scheme", "http", // at this point there is no way to get a container IP // before the container started, so setting "localhost" "-external-url", "http://localhost:" + fakeGcsContainerPort )); @Test void testWithFakeGcs() { var storageService = StorageOptions.newBuilder() .setHost("http://localhost:" + fakeGcs.getFirstMappedPort()) .setProjectId("test-project") .setCredentials(NoCredentials.getInstance()) .build() .getService(); WriteChannel channel = storageService.writer(BlobInfo.newBuilder("sample-bucket2", "some_file2.txt").build()); channel.write(ByteBuffer.wrap("line1\n".getBytes())); channel.write(ByteBuffer.wrap("line2\n".getBytes())); channel.close(); // <- ERROR on CI environment expected! } ``` The solution proposed is to modify fake-gcs-server configuration AFTER the container is eventually started and container IP is known: ``` String fakeGcsExternalUrl = "http://" + fakeGcs.getContainerIpAddress() + ":" + fakeGcs.getFirstMappedPort(); updateExternalUrlWithContainerUrl(fakeGcsExternalUrl); ``` See the full example at https://github.com/sergseven/fake-gcs-server/blob/upload-content-fix/examples/java/README.md#resumable-upload-operations-and-containerised-fake-gcs-server --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-03 12:31:42 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/fake-gcs-server#803
No description provided.