Skip to content

Commit

Permalink
Use Target Architecture Argument for docker build (#726)
Browse files Browse the repository at this point in the history
In the spanner emulator, a version of wrench is downloaded. But it is hardcoded to amd64.

This change uses the auto populated TARGETARCH argument.

Now, we know which architecture to use when downloading the wrench CLI. Should fix the problem for those running the repo on a Macbook.

See: #720 (comment)
  • Loading branch information
jcscottiii authored Oct 14, 2024
1 parent 52918c6 commit 71ef56f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions .dev/spanner/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@
# limitations under the License.

FROM google/cloud-sdk:495.0.0-emulators
# TARGETARCH is an automatic platform ARG enabled by Docker BuildKit.
# https://docs.docker.com/reference/dockerfile/#automatic-platform-args-in-the-global-scope
ARG TARGETARCH

ENV SPANNER_PROJECT_ID=local
ENV SPANNER_INSTANCE_ID=local
ENV SPANNER_DATABASE_ID=local
ENV SPANNER_EMULATOR_HOST=0.0.0.0:9010

# Install Wrench - https://github.com/cloudspannerecosystem/wrench
ENV WRENCH_VERSION="1.7.0"
ENV WRENCH_VERSION="1.10.1"
RUN echo "Downloading for version ${WRENCH_VERSION} for architecture ${TARGETARCH}"
RUN curl \
-L -o wrench.tar.gz \
"https://github.com/cloudspannerecosystem/wrench/releases/download/v${WRENCH_VERSION}/wrench-${WRENCH_VERSION}-linux-amd64.tar.gz" && \
"https://github.com/cloudspannerecosystem/wrench/releases/download/v${WRENCH_VERSION}/wrench-${WRENCH_VERSION}-linux-${TARGETARCH}.tar.gz" && \
tar -xf wrench.tar.gz && mv wrench /bin/

RUN gcloud config set auth/disable_credentials true && \
Expand Down
4 changes: 4 additions & 0 deletions lib/gcpspanner/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"path/filepath"
"reflect"
"runtime"
"testing"
"time"

Expand Down Expand Up @@ -64,10 +65,13 @@ func createDatabaseContainer() error {
if err != nil {
return err
}

goarch := runtime.GOARCH
req := testcontainers.ContainerRequest{
FromDockerfile: testcontainers.FromDockerfile{
Dockerfile: filepath.Join(".dev", "spanner", "Dockerfile"),
Context: repoRoot,
BuildArgs: map[string]*string{"TARGETARCH": &goarch},
},
ExposedPorts: []string{"9010/tcp"},
WaitingFor: wait.ForLog("Spanner setup for webstatus.dev finished"),
Expand Down

0 comments on commit 71ef56f

Please sign in to comment.