From 4c150b6b11539bb1b89dfd1d210692ec58e93113 Mon Sep 17 00:00:00 2001 From: Qiao Han Date: Wed, 24 Jul 2024 01:32:26 +0800 Subject: [PATCH 01/14] fix: pin bubbletea to avoid messing up line breaks --- go.mod | 8 ++------ go.sum | 17 ++++------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index d1c950de4..a1eb00a9a 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/andybalholm/brotli v1.1.0 github.com/cenkalti/backoff/v4 v4.3.0 github.com/charmbracelet/bubbles v0.18.0 - github.com/charmbracelet/bubbletea v0.26.6 + github.com/charmbracelet/bubbletea v0.25.0 github.com/charmbracelet/glamour v0.7.0 github.com/charmbracelet/lipgloss v0.12.1 github.com/containers/common v0.59.2 @@ -102,14 +102,12 @@ require ( github.com/charithe/durationcheck v0.0.10 // indirect github.com/charmbracelet/harmonica v0.2.0 // indirect github.com/charmbracelet/x/ansi v0.1.4 // indirect - github.com/charmbracelet/x/input v0.1.0 // indirect - github.com/charmbracelet/x/term v0.1.1 // indirect - github.com/charmbracelet/x/windows v0.1.0 // indirect github.com/chavacava/garif v0.1.0 // indirect github.com/ckaznocha/intrange v0.1.2 // indirect github.com/cloudflare/circl v1.3.7 // indirect github.com/cloudwego/base64x v0.1.4 // indirect github.com/cloudwego/iasm v0.2.0 // indirect + github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect github.com/containerd/log v0.1.0 // indirect github.com/containers/storage v1.54.0 // indirect github.com/curioswitch/go-reassign v0.2.0 // indirect @@ -126,7 +124,6 @@ require ( github.com/docker/go v1.5.1-1.0.20160303222718-d30aec9fd63c // indirect github.com/docker/go-metrics v0.0.1 // indirect github.com/emirpasic/gods v1.18.1 // indirect - github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect github.com/ettle/strcase v0.2.0 // indirect github.com/fatih/color v1.17.0 // indirect github.com/fatih/structtag v1.2.0 // indirect @@ -311,7 +308,6 @@ require ( github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect github.com/xeipuuv/gojsonschema v1.2.0 // indirect github.com/xen0n/gosmopolitan v1.2.2 // indirect - github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect github.com/yagipy/maintidx v1.0.0 // indirect github.com/yeya24/promlinter v0.3.0 // indirect github.com/ykadowak/zerologlint v0.1.5 // indirect diff --git a/go.sum b/go.sum index 3db1fa6e1..5358852b8 100644 --- a/go.sum +++ b/go.sum @@ -166,8 +166,8 @@ github.com/charithe/durationcheck v0.0.10 h1:wgw73BiocdBDQPik+zcEoBG/ob8uyBHf2iy github.com/charithe/durationcheck v0.0.10/go.mod h1:bCWXb7gYRysD1CU3C+u4ceO49LoGOY1C1L6uouGNreQ= github.com/charmbracelet/bubbles v0.18.0 h1:PYv1A036luoBGroX6VWjQIE9Syf2Wby2oOl/39KLfy0= github.com/charmbracelet/bubbles v0.18.0/go.mod h1:08qhZhtIwzgrtBjAcJnij1t1H0ZRjwHyGsy6AL11PSw= -github.com/charmbracelet/bubbletea v0.26.6 h1:zTCWSuST+3yZYZnVSvbXwKOPRSNZceVeqpzOLN2zq1s= -github.com/charmbracelet/bubbletea v0.26.6/go.mod h1:dz8CWPlfCCGLFbBlTY4N7bjLiyOGDJEnd2Muu7pOWhk= +github.com/charmbracelet/bubbletea v0.25.0 h1:bAfwk7jRz7FKFl9RzlIULPkStffg5k6pNt5dywy4TcM= +github.com/charmbracelet/bubbletea v0.25.0/go.mod h1:EN3QDR1T5ZdWmdfDzYcqOCAps45+QIJbLOBxmVNWNNg= github.com/charmbracelet/glamour v0.7.0 h1:2BtKGZ4iVJCDfMF229EzbeR1QRKLWztO9dMtjmqZSng= github.com/charmbracelet/glamour v0.7.0/go.mod h1:jUMh5MeihljJPQbJ/wf4ldw2+yBP59+ctV36jASy7ps= github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ= @@ -176,12 +176,6 @@ github.com/charmbracelet/lipgloss v0.12.1 h1:/gmzszl+pedQpjCOH+wFkZr/N90Snz40J/N github.com/charmbracelet/lipgloss v0.12.1/go.mod h1:V2CiwIuhx9S1S1ZlADfOj9HmxeMAORuz5izHb0zGbB8= github.com/charmbracelet/x/ansi v0.1.4 h1:IEU3D6+dWwPSgZ6HBH+v6oUuZ/nVawMiWj5831KfiLM= github.com/charmbracelet/x/ansi v0.1.4/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= -github.com/charmbracelet/x/input v0.1.0 h1:TEsGSfZYQyOtp+STIjyBq6tpRaorH0qpwZUj8DavAhQ= -github.com/charmbracelet/x/input v0.1.0/go.mod h1:ZZwaBxPF7IG8gWWzPUVqHEtWhc1+HXJPNuerJGRGZ28= -github.com/charmbracelet/x/term v0.1.1 h1:3cosVAiPOig+EV4X9U+3LDgtwwAoEzJjNdwbXDjF6yI= -github.com/charmbracelet/x/term v0.1.1/go.mod h1:wB1fHt5ECsu3mXYusyzcngVWWlu1KKUmmLhfgr/Flxw= -github.com/charmbracelet/x/windows v0.1.0 h1:gTaxdvzDM5oMa/I2ZNF7wN78X/atWemG9Wph7Ika2k4= -github.com/charmbracelet/x/windows v0.1.0/go.mod h1:GLEO/l+lizvFDBPLIOk+49gdX49L9YWMB5t+DZd0jkQ= github.com/chavacava/garif v0.1.0 h1:2JHa3hbYf5D9dsgseMKAmc/MZ109otzgNFk5s87H9Pc= github.com/chavacava/garif v0.1.0/go.mod h1:XMyYCkEL58DF0oyW4qDjjnPWONs2HBqYKI+UIPD+Gww= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= @@ -202,6 +196,8 @@ github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I= github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= +github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY= +github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk= github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= github.com/containers/common v0.59.2 h1:FcURZzlMYMVZXqjMEop6C0A3yWilrfmWUPUw09APHvI= @@ -268,8 +264,6 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4= -github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM= github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0= github.com/ettle/strcase v0.2.0 h1:fGNiVF21fHXpX1niBgk0aROov1LagYsOwV/xqKDKR/Q= github.com/ettle/strcase v0.2.0/go.mod h1:DajmHElDSaX76ITe3/VHVyMin4LWSJN5Z909Wp+ED1A= @@ -998,8 +992,6 @@ github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17 github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= github.com/xen0n/gosmopolitan v1.2.2 h1:/p2KTnMzwRexIW8GlKawsTWOxn7UHA+jCMF/V8HHtvU= github.com/xen0n/gosmopolitan v1.2.2/go.mod h1:7XX7Mj61uLYrj0qmeN0zi7XDon9JRAEhYQqAPLVNTeg= -github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= -github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= github.com/yagipy/maintidx v1.0.0 h1:h5NvIsCz+nRDapQ0exNv4aJ0yXSI0420omVANTv3GJM= github.com/yagipy/maintidx v1.0.0/go.mod h1:0qNf/I/CCZXSMhsRsrEPDZ+DkekpKLXAJfsTACwgXLk= github.com/yeya24/promlinter v0.3.0 h1:JVDbMp08lVCP7Y6NP3qHroGAO6z2yGKQtS5JsjqtoFs= @@ -1279,7 +1271,6 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211105183446-c75c47738b0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= From 3f88398c18c4c8e5bff6336b570e2cc975c620ca Mon Sep 17 00:00:00 2001 From: Qiao Han Date: Wed, 24 Jul 2024 01:33:06 +0800 Subject: [PATCH 02/14] chore: update dependabot to ignore 0 major version --- .github/workflows/automerge.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index a0495fa1d..1e57b0afd 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -17,24 +17,22 @@ jobs: # This first step will fail if there's no metadata and so the approval # will not occur. - name: Dependabot metadata - id: dependabot-metadata + id: meta uses: dependabot/fetch-metadata@v2 with: github-token: "${{ secrets.GITHUB_TOKEN }}" # Here the PR gets approved. - name: Approve a PR - if: ${{ steps.dependabot-metadata.outputs.update-type != 'version-update:semver-major' }} - run: gh pr review --approve "$PR_URL" + if: ${{ steps.meta.outputs.update-type == 'version-update:semver-patch' || (!startsWith(steps.meta.outputs.previous-version, '0.') && steps.meta.outputs.update-type == 'version-update:semver-minor') }} + run: gh pr review --approve "${{ github.event.pull_request.html_url }}" env: - PR_URL: ${{ github.event.pull_request.html_url }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Finally, this sets the PR to allow auto-merging for patch and minor # updates if all checks pass - name: Enable auto-merge for Dependabot PRs - if: ${{ steps.dependabot-metadata.outputs.update-type != 'version-update:semver-major' }} - run: gh pr merge --auto --squash "$PR_URL" + if: ${{ steps.meta.outputs.update-type == 'version-update:semver-patch' || (!startsWith(steps.meta.outputs.previous-version, '0.') && steps.meta.outputs.update-type == 'version-update:semver-minor') }} + run: gh pr merge --auto --squash "${{ github.event.pull_request.html_url }}" env: - PR_URL: ${{ github.event.pull_request.html_url }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From ec053f8ba858b41655b2793bd6cfe8dcf9354212 Mon Sep 17 00:00:00 2001 From: Qiao Han Date: Wed, 24 Jul 2024 01:37:32 +0800 Subject: [PATCH 03/14] chore: update indirect dependencies --- go.mod | 36 +++++++++++++++---------------- go.sum | 68 +++++++++++++++++++++++++++++----------------------------- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/go.mod b/go.mod index a1eb00a9a..df5e501f0 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/supabase/cli -go 1.22.3 +go 1.22.4 require ( github.com/BurntSushi/toml v1.4.0 @@ -139,7 +139,7 @@ require ( github.com/go-critic/go-critic v0.11.4 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect github.com/go-git/go-billy/v5 v5.5.0 // indirect - github.com/go-logr/logr v1.4.1 // indirect + github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-openapi/jsonpointer v0.21.0 // indirect github.com/go-openapi/swag v0.23.0 // indirect @@ -227,19 +227,19 @@ require ( github.com/mattn/go-runewidth v0.0.15 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect github.com/mgechev/revive v1.3.7 // indirect - github.com/microcosm-cc/bluemonday v1.0.26 // indirect + github.com/microcosm-cc/bluemonday v1.0.25 // indirect github.com/miekg/pkcs11 v1.1.1 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect github.com/moby/docker-image-spec v1.3.1 // indirect - github.com/moby/sys/sequential v0.5.0 // indirect + github.com/moby/sys/sequential v0.6.0 // indirect github.com/moby/term v0.5.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect github.com/moricho/tparallel v0.3.1 // indirect github.com/morikuni/aec v1.0.0 // indirect - github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect + github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect github.com/muesli/cancelreader v0.2.2 // indirect github.com/muesli/termenv v0.15.2 // indirect github.com/nakabonne/nestif v0.3.1 // indirect @@ -317,16 +317,16 @@ require ( go-simpler.org/musttag v0.12.2 // indirect go-simpler.org/sloglint v0.7.1 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect - go.opentelemetry.io/otel v1.27.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.27.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0 // indirect - go.opentelemetry.io/otel/metric v1.27.0 // indirect - go.opentelemetry.io/otel/sdk v1.27.0 // indirect - go.opentelemetry.io/otel/sdk/metric v1.27.0 // indirect - go.opentelemetry.io/otel/trace v1.27.0 // indirect - go.opentelemetry.io/proto/otlp v1.2.0 // indirect + go.opentelemetry.io/otel v1.28.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.28.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0 // indirect + go.opentelemetry.io/otel/metric v1.28.0 // indirect + go.opentelemetry.io/otel/sdk v1.28.0 // indirect + go.opentelemetry.io/otel/sdk/metric v1.28.0 // indirect + go.opentelemetry.io/otel/trace v1.28.0 // indirect + go.opentelemetry.io/proto/otlp v1.3.1 // indirect go.uber.org/atomic v1.9.0 // indirect go.uber.org/automaxprocs v1.5.3 // indirect go.uber.org/multierr v1.9.0 // indirect @@ -340,9 +340,9 @@ require ( golang.org/x/sys v0.22.0 // indirect golang.org/x/text v0.16.0 // indirect golang.org/x/tools v0.22.0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect - google.golang.org/protobuf v1.34.1 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect + google.golang.org/protobuf v1.34.2 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 5358852b8..9dd3bac96 100644 --- a/go.sum +++ b/go.sum @@ -322,8 +322,8 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9 github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= -github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= @@ -704,8 +704,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0j github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mgechev/revive v1.3.7 h1:502QY0vQGe9KtYJ9FpxMz9rL+Fc/P13CI5POL4uHCcE= github.com/mgechev/revive v1.3.7/go.mod h1:RJ16jUbF0OWC3co/+XTxmFNgEpUPwnnA0BRllX2aDNA= -github.com/microcosm-cc/bluemonday v1.0.26 h1:xbqSvqzQMeEHCqMi64VAs4d8uy6Mequs3rQ0k/Khz58= -github.com/microcosm-cc/bluemonday v1.0.26/go.mod h1:JyzOCs9gkyQyjs+6h10UEVSe02CGwkhd72Xdqh78TWs= +github.com/microcosm-cc/bluemonday v1.0.25 h1:4NEwSfiJ+Wva0VxN5B8OwMicaJvD8r9tlJWm9rtloEg= +github.com/microcosm-cc/bluemonday v1.0.25/go.mod h1:ZIOjCQp1OrzBBPIJmfX4qDYFuhU02nx4bn030ixfHLE= github.com/miekg/pkcs11 v1.0.2/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs= github.com/miekg/pkcs11 v1.1.1 h1:Ugu9pdy6vAYku5DEpVWVFPYnzV+bxB+iRdbuFSu7TvU= github.com/miekg/pkcs11 v1.1.1/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs= @@ -718,8 +718,8 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0= github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo= -github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5lXtc= -github.com/moby/sys/sequential v0.5.0/go.mod h1:tH2cOOs5V9MlPiXcQzRC+eEyab644PWKGRYaaV5ZZlo= +github.com/moby/sys/sequential v0.6.0 h1:qrx7XFUd/5DxtqcoH1h438hF5TmOvzC/lspjy7zgvCU= +github.com/moby/sys/sequential v0.6.0/go.mod h1:uyv8EUTrca5PnDsdMGXhZe6CCe8U/UiTWd+lL+7b/Ko= github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -735,8 +735,8 @@ github.com/moricho/tparallel v0.3.1 h1:fQKD4U1wRMAYNngDonW5XupoB/ZGJHdpzrWqgyg9k github.com/moricho/tparallel v0.3.1/go.mod h1:leENX2cUv7Sv2qDgdi0D0fCftN8fRC67Bcn8pqzeYNI= github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= -github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI= -github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo= +github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34= +github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho= github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= @@ -1028,26 +1028,26 @@ go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 h1:jq9TW8u3so/bN+JPT166wjOI6/vQPF6Xe7nMNIltagk= go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0/go.mod h1:p8pYQP+m5XfbZm9fxtSKAbM6oIllS7s2AfxrChvc7iw= -go.opentelemetry.io/otel v1.27.0 h1:9BZoF3yMK/O1AafMiQTVu0YDj5Ea4hPhxCs7sGva+cg= -go.opentelemetry.io/otel v1.27.0/go.mod h1:DMpAK8fzYRzs+bi3rS5REupisuqTheUlSZJ1WnZaPAQ= -go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.27.0 h1:bFgvUr3/O4PHj3VQcFEuYKvRZJX1SJDQ+11JXuSB3/w= -go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.27.0/go.mod h1:xJntEd2KL6Qdg5lwp97HMLQDVeAhrYxmzFseAMDPQ8I= -go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0 h1:R9DE4kQ4k+YtfLI2ULwX82VtNQ2J8yZmA7ZIF/D+7Mc= -go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.27.0/go.mod h1:OQFyQVrDlbe+R7xrEyDr/2Wr67Ol0hRUgsfA+V5A95s= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 h1:qFffATk0X+HD+f1Z8lswGiOQYKHRlzfmdJm0wEaVrFA= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0/go.mod h1:MOiCmryaYtc+V0Ei+Tx9o5S1ZjA7kzLucuVuyzBZloQ= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0 h1:QY7/0NeRPKlzusf40ZE4t1VlMKbqSNT7cJRYzWuja0s= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.27.0/go.mod h1:HVkSiDhTM9BoUJU8qE6j2eSWLLXvi1USXjyd2BXT8PY= -go.opentelemetry.io/otel/metric v1.27.0 h1:hvj3vdEKyeCi4YaYfNjv2NUje8FqKqUY8IlF0FxV/ik= -go.opentelemetry.io/otel/metric v1.27.0/go.mod h1:mVFgmRlhljgBiuk/MP/oKylr4hs85GZAylncepAX/ak= -go.opentelemetry.io/otel/sdk v1.27.0 h1:mlk+/Y1gLPLn84U4tI8d3GNJmGT/eXe3ZuOXN9kTWmI= -go.opentelemetry.io/otel/sdk v1.27.0/go.mod h1:Ha9vbLwJE6W86YstIywK2xFfPjbWlCuwPtMkKdz/Y4A= -go.opentelemetry.io/otel/sdk/metric v1.27.0 h1:5uGNOlpXi+Hbo/DRoI31BSb1v+OGcpv2NemcCrOL8gI= -go.opentelemetry.io/otel/sdk/metric v1.27.0/go.mod h1:we7jJVrYN2kh3mVBlswtPU22K0SA+769l93J6bsyvqw= -go.opentelemetry.io/otel/trace v1.27.0 h1:IqYb813p7cmbHk0a5y6pD5JPakbVfftRXABGt5/Rscw= -go.opentelemetry.io/otel/trace v1.27.0/go.mod h1:6RiD1hkAprV4/q+yd2ln1HG9GoPx39SuvvstaLBl+l4= -go.opentelemetry.io/proto/otlp v1.2.0 h1:pVeZGk7nXDC9O2hncA6nHldxEjm6LByfA2aN8IOkz94= -go.opentelemetry.io/proto/otlp v1.2.0/go.mod h1:gGpR8txAl5M03pDhMC79G6SdqNV26naRm/KDsgaHD8A= +go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo= +go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.28.0 h1:U2guen0GhqH8o/G2un8f/aG/y++OuW6MyCo6hT9prXk= +go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.28.0/go.mod h1:yeGZANgEcpdx/WK0IvvRFC+2oLiMS2u4L/0Rj2M2Qr0= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 h1:3Q/xZUyC1BBkualc9ROb4G8qkH90LXEIICcs5zv1OYY= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0/go.mod h1:s75jGIWA9OfCMzF0xr+ZgfrB5FEbbV7UuYo32ahUiFI= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0 h1:R3X6ZXmNPRR8ul6i3WgFURCHzaXjHdm0karRG/+dj3s= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.28.0/go.mod h1:QWFXnDavXWwMx2EEcZsf3yxgEKAqsxQ+Syjp+seyInw= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0 h1:j9+03ymgYhPKmeXGk5Zu+cIZOlVzd9Zv7QIiyItjFBU= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0/go.mod h1:Y5+XiUG4Emn1hTfciPzGPJaSI+RpDts6BnCIir0SLqk= +go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q= +go.opentelemetry.io/otel/metric v1.28.0/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s= +go.opentelemetry.io/otel/sdk v1.28.0 h1:b9d7hIry8yZsgtbmM0DKyPWMMUMlK9NEKuIG4aBqWyE= +go.opentelemetry.io/otel/sdk v1.28.0/go.mod h1:oYj7ClPUA7Iw3m+r7GeEjz0qckQRJK2B8zjcZEfu7Pg= +go.opentelemetry.io/otel/sdk/metric v1.28.0 h1:OkuaKgKrgAbYrrY0t92c+cC+2F6hsFNnCQArXCKlg08= +go.opentelemetry.io/otel/sdk/metric v1.28.0/go.mod h1:cWPjykihLAPvXKi4iZc1dpER3Jdq2Z0YLse3moQUCpg= +go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g= +go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI= +go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeXrui0= +go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= @@ -1462,10 +1462,10 @@ google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7Fc google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 h1:7whR9kGa5LUwFtpLm2ArCEejtnxlGeLbAyjFY8sGNFw= -google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157/go.mod h1:99sLkeliLXfdj2J75X3Ho+rrVCaJze0uwN7zDDkjPVU= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 h1:Zy9XzmMEflZ/MAaA7vNcoebnRAld7FsPW1EeBB7V0m8= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0= +google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094 h1:0+ozOGcrp+Y8Aq8TLNN2Aliibms5LEzsq99ZZmAGYm0= +google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094/go.mod h1:fJ/e3If/Q67Mj99hin0hMhiNyCRmt6BQ2aWIJshUSJw= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 h1:BwIjyKYGsK9dMCBOorzRri8MQwmi7mT9rGHsCEinZkA= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= google.golang.org/grpc v1.0.5/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= @@ -1493,8 +1493,8 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= -google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/cenkalti/backoff.v2 v2.2.1 h1:eJ9UAg01/HIHG987TwxvnzK2MgxXq97YY6rYDpY9aII= From 821da8fec7c43073d0b41e497deaf4a9cd445d4a Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Wed, 24 Jul 2024 12:20:25 +0800 Subject: [PATCH 04/14] fix: use http scheme for vector docker host (#2545) --- internal/functions/deploy/bundle.go | 2 ++ internal/functions/serve/serve.go | 1 + internal/start/start.go | 37 +++++++++++++++++++---------- internal/utils/docker.go | 1 + internal/utils/docker_linux.go | 2 +- pkg/config/config_test.go | 4 ++-- 6 files changed, 32 insertions(+), 15 deletions(-) diff --git a/internal/functions/deploy/bundle.go b/internal/functions/deploy/bundle.go index 7e60ad0b4..0b178b0f7 100644 --- a/internal/functions/deploy/bundle.go +++ b/internal/functions/deploy/bundle.go @@ -96,6 +96,7 @@ func GetBindMounts(cwd, hostFuncDir, hostOutputDir, hostEntrypointDir, hostImpor hostFuncDir += sep } dockerFuncDir := utils.ToDockerPath(hostFuncDir) + // TODO: bind ./supabase/functions:/home/deno/functions to hide PII? binds := []string{ // Reuse deno cache directory, ie. DENO_DIR, between container restarts // https://denolib.gitbook.io/guide/advanced/deno_dir-code-fetch-and-cache @@ -128,6 +129,7 @@ func GetBindMounts(cwd, hostFuncDir, hostOutputDir, hostEntrypointDir, hostImpor binds = append(binds, hostEntrypointDir+":"+dockerEntrypointDir+":ro") } } + // Imports outside of ./supabase/functions will be bound by absolute path if len(hostImportMapPath) > 0 { if !filepath.IsAbs(hostImportMapPath) { hostImportMapPath = filepath.Join(cwd, hostImportMapPath) diff --git a/internal/functions/serve/serve.go b/internal/functions/serve/serve.go index 481ed206c..290d52ac4 100644 --- a/internal/functions/serve/serve.go +++ b/internal/functions/serve/serve.go @@ -225,6 +225,7 @@ func populatePerFunctionConfigs(cwd, importMapPath string, noVerifyJWT *bool, fs } binds = append(binds, modules...) fc.ImportMap = utils.ToDockerPath(fc.ImportMap) + fc.Entrypoint = utils.ToDockerPath(fc.Entrypoint) functionsConfig[slug] = fc } functionsConfigBytes, err := json.Marshal(functionsConfig) diff --git a/internal/start/start.go b/internal/start/start.go index ae703f81b..4fd30383d 100644 --- a/internal/start/start.go +++ b/internal/start/start.go @@ -5,6 +5,8 @@ import ( "context" _ "embed" "fmt" + "net" + "net/url" "os" "path" "path/filepath" @@ -275,27 +277,38 @@ EOF }); err != nil { return errors.Errorf("failed to exec template: %w", err) } - var binds []string - env := []string{ - "VECTOR_CONFIG=/etc/vector/vector.yaml", - } + var binds, env []string // Special case for GitLab pipeline - host := utils.Docker.DaemonHost() - if parsed, err := client.ParseHostURL(host); err == nil && parsed.Scheme == "tcp" { - parsed.Host = "host.docker.internal" - env = append(env, "DOCKER_HOST="+parsed.String()) - } else if parsed, err := client.ParseHostURL(client.DefaultDockerHost); err == nil { - if host != client.DefaultDockerHost { + parsed, err := client.ParseHostURL(utils.Docker.DaemonHost()) + if err != nil { + return errors.Errorf("failed to parse docker host: %w", err) + } + // Ref: https://vector.dev/docs/reference/configuration/sources/docker_logs/#docker_host + dindHost := url.URL{Scheme: "http", Host: net.JoinHostPort(utils.DinDHost, "2375")} + switch parsed.Scheme { + case "tcp": + if _, port, err := net.SplitHostPort(parsed.Host); err == nil { + dindHost.Host = net.JoinHostPort(utils.DinDHost, port) + } + env = append(env, "DOCKER_HOST="+dindHost.String()) + case "npipe": + fmt.Fprintln(os.Stderr, utils.Yellow("WARNING:"), "analytics requires docker daemon exposed on tcp://localhost:2375") + env = append(env, "DOCKER_HOST="+dindHost.String()) + case "unix": + if parsed, err = client.ParseHostURL(client.DefaultDockerHost); err != nil { + return errors.Errorf("failed to parse default host: %w", err) + } + if utils.Docker.DaemonHost() != client.DefaultDockerHost { fmt.Fprintln(os.Stderr, utils.Yellow("WARNING:"), "analytics requires mounting default docker socket:", parsed.Host) } - binds = append(binds, parsed.Host+":/var/run/docker.sock:ro") + binds = append(binds, fmt.Sprintf("%[1]s:%[1]s:ro", parsed.Host)) } if _, err := utils.DockerStart( ctx, container.Config{ Image: utils.Config.Analytics.VectorImage, Env: env, - Entrypoint: []string{"sh", "-c", `cat <<'EOF' > /etc/vector/vector.yaml && vector + Entrypoint: []string{"sh", "-c", `cat <<'EOF' > /etc/vector/vector.yaml && vector --config /etc/vector/vector.yaml ` + vectorConfigBuf.String() + ` EOF `}, diff --git a/internal/utils/docker.go b/internal/utils/docker.go index 093c459c3..3d80f8f59 100644 --- a/internal/utils/docker.go +++ b/internal/utils/docker.go @@ -50,6 +50,7 @@ func NewDocker() *client.Client { } const ( + DinDHost = "host.docker.internal" CliProjectLabel = "com.supabase.cli.project" composeProjectLabel = "com.docker.compose.project" ) diff --git a/internal/utils/docker_linux.go b/internal/utils/docker_linux.go index 392fec4eb..b5463d060 100644 --- a/internal/utils/docker_linux.go +++ b/internal/utils/docker_linux.go @@ -5,7 +5,7 @@ package utils import "github.com/docker/docker/api/types/container" // Allows containers to resolve host network: https://stackoverflow.com/a/62431165 -var extraHosts = []string{"host.docker.internal:host-gateway"} +var extraHosts = []string{DinDHost + ":host-gateway"} func isUserDefined(mode container.NetworkMode) bool { return mode.IsUserDefined() diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 85b7a5720..29a605059 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -151,8 +151,8 @@ func TestSigningJWT(t *testing.T) { }) t.Run("signs default service_role key", func(t *testing.T) { - anonToken := CustomClaims{Role: "service_role"}.NewToken() - signed, err := anonToken.SignedString([]byte(defaultJwtSecret)) + serviceToken := CustomClaims{Role: "service_role"}.NewToken() + signed, err := serviceToken.SignedString([]byte(defaultJwtSecret)) assert.NoError(t, err) assert.Equal(t, defaultServiceRoleKey, signed) }) From 75c359d79b88e2f83bb0847ce7c37f303afb5986 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 25 Jul 2024 04:51:07 +0000 Subject: [PATCH 05/14] chore(deps): bump tar from 7.4.1 to 7.4.2 (#2554) Bumps [tar](https://github.com/isaacs/node-tar) from 7.4.1 to 7.4.2. - [Release notes](https://github.com/isaacs/node-tar/releases) - [Changelog](https://github.com/isaacs/node-tar/blob/main/CHANGELOG.md) - [Commits](https://github.com/isaacs/node-tar/compare/v7.4.1...v7.4.2) --- updated-dependencies: - dependency-name: tar dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7fc3f3888..c37061378 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "bin-links": "^4.0.3", "https-proxy-agent": "^7.0.2", "node-fetch": "^3.3.2", - "tar": "7.4.1" + "tar": "7.4.2" }, "release": { "branches": [ From 1179ca6599ccdf497153449208b554156ae77744 Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Fri, 26 Jul 2024 00:18:50 +0800 Subject: [PATCH 06/14] fix(db): bump postgres version for new wrappers (#2555) --- pkg/config/constants.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/config/constants.go b/pkg/config/constants.go index e42369062..248bd8e2e 100644 --- a/pkg/config/constants.go +++ b/pkg/config/constants.go @@ -3,7 +3,7 @@ package config const ( pg13Image = "supabase/postgres:13.3.0" pg14Image = "supabase/postgres:14.1.0.89" - Pg15Image = "supabase/postgres:15.1.1.61" + Pg15Image = "supabase/postgres:15.1.1.78" // Append to ServiceImages when adding new dependencies below // TODO: try https://github.com/axllent/mailpit kongImage = "library/kong:2.8.1" From d4fc8469a4dbc62e84eeafefc05954e2cde308d7 Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Fri, 26 Jul 2024 00:19:05 +0800 Subject: [PATCH 07/14] fix(studio): bump to latest version (#2550) --- pkg/config/constants.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/config/constants.go b/pkg/config/constants.go index 248bd8e2e..27facbca0 100644 --- a/pkg/config/constants.go +++ b/pkg/config/constants.go @@ -10,7 +10,7 @@ const ( inbucketImage = "inbucket/inbucket:3.0.3" postgrestImage = "postgrest/postgrest:v12.2.0" pgmetaImage = "supabase/postgres-meta:v0.83.2" - studioImage = "supabase/studio:20240701-05dfbec" + studioImage = "supabase/studio:20240722-c670708" imageProxyImage = "darthsim/imgproxy:v3.8.0" edgeRuntimeImage = "supabase/edge-runtime:v1.55.0" vectorImage = "timberio/vector:0.28.1-alpine" From dd2b65fdcb1f8c8c81110549dd3cc76e1a0400e7 Mon Sep 17 00:00:00 2001 From: Han Qiao Date: Fri, 26 Jul 2024 00:19:16 +0800 Subject: [PATCH 08/14] chore: add code examples for using supabase pkg (#2556) --- examples/README.md | 34 +++++++++++++++++++++ examples/functions-deploy/main.go | 49 +++++++++++++++++++++++++++++++ examples/migrations-up/main.go | 31 +++++++++++++++++++ examples/seed-buckets/main.go | 42 ++++++++++++++++++++++++++ 4 files changed, 156 insertions(+) create mode 100644 examples/README.md create mode 100644 examples/functions-deploy/main.go create mode 100644 examples/migrations-up/main.go create mode 100644 examples/seed-buckets/main.go diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 000000000..bf6a62c2e --- /dev/null +++ b/examples/README.md @@ -0,0 +1,34 @@ +## Code examples using CLI library + +The examples in this directory demonstrate the minimal code to get started with building your own tools for managing Supabase projects. If you are a 3rd party service provider looking for ways to integrate with Supabase user projects, you may want to use the building blocks provided by this library. + +All examples come with an entrypoint that you can build and run locally. + +### Deploy functions + +```bash +# Place your functions under supabase/functions +export SUPABASE_PROJECT_ID="zeoxvqpvpyrxygmmatng" +export SUPABASE_ACCESS_TOKEN="sbp_..." +go run examples/deploy-functions/main.go +``` + +### Migrate database + +```bash +# Place your schemas under supabase/migrations +export PGHOST="db.zeoxvqpvpyrxygmmatng.supabase.co" +export PGPORT="5432" +export PGUSER="postgres" +export PGPASS="" +export PGDATABASE="postgres" +go run examples/migrate-database/main.go +``` + +### Seed storage buckets + +```bash +export SUPABASE_PROJECT_ID="zeoxvqpvpyrxygmmatng" +export SUPABASE_SERVICE_ROLE_KEY="eyJh..." +go run examples/migrate-database/main.go +``` diff --git a/examples/functions-deploy/main.go b/examples/functions-deploy/main.go new file mode 100644 index 000000000..716ef1462 --- /dev/null +++ b/examples/functions-deploy/main.go @@ -0,0 +1,49 @@ +package main + +import ( + "context" + "io/fs" + "log" + "net/http" + "os" + "time" + + "github.com/supabase/cli/pkg/api" + "github.com/supabase/cli/pkg/config" + "github.com/supabase/cli/pkg/function" +) + +func main() { + if err := deploy(context.Background(), os.DirFS(".")); err != nil { + log.Fatalln(err) + } +} + +// Requires edge runtime binary to be added to PATH +func deploy(ctx context.Context, fsys fs.FS) error { + project := os.Getenv("SUPABASE_PROJECT_ID") + apiClient := newAPIClient(os.Getenv("SUPABASE_ACCESS_TOKEN")) + eszipBundler := function.NewNativeBundler(".", fsys) + functionClient := function.NewEdgeRuntimeAPI(project, apiClient, eszipBundler) + fc := config.FunctionConfig{"my-slug": { + Entrypoint: "supabase/functions/my-slug/index.ts", + ImportMap: "supabase/functions/import_map.json", + }} + return functionClient.UpsertFunctions(ctx, fc) +} + +func newAPIClient(token string) api.ClientWithResponses { + header := func(ctx context.Context, req *http.Request) error { + req.Header.Set("Authorization", "Bearer "+token) + return nil + } + client := api.ClientWithResponses{ClientInterface: &api.Client{ + // Ensure the server URL always has a trailing slash + Server: "https://api.supabase.com/", + Client: &http.Client{ + Timeout: 10 * time.Second, + }, + RequestEditors: []api.RequestEditorFn{header}, + }} + return client +} diff --git a/examples/migrations-up/main.go b/examples/migrations-up/main.go new file mode 100644 index 000000000..3ef03242b --- /dev/null +++ b/examples/migrations-up/main.go @@ -0,0 +1,31 @@ +package main + +import ( + "context" + "io/fs" + "log" + "os" + + "github.com/supabase/cli/pkg/migration" + "github.com/supabase/cli/pkg/pgxv5" +) + +func main() { + if err := migrate(context.Background(), os.DirFS(".")); err != nil { + log.Fatalln(err) + } +} + +// Applies local migrations to a remote database, and tracks the history of executed statements. +func migrate(ctx context.Context, fsys fs.FS) error { + conn, err := pgxv5.Connect(ctx, os.Getenv("SUPABASE_POSTGRES_URL")) + if err != nil { + return err + } + defer conn.Close(ctx) + files, err := migration.ListLocalMigrations("supabase/migrations", fsys) + if err != nil { + return err + } + return migration.ApplyMigrations(ctx, files, conn, fsys) +} diff --git a/examples/seed-buckets/main.go b/examples/seed-buckets/main.go new file mode 100644 index 000000000..2c62b1084 --- /dev/null +++ b/examples/seed-buckets/main.go @@ -0,0 +1,42 @@ +package main + +import ( + "context" + "fmt" + "log" + "net/http" + "os" + "time" + + "github.com/supabase/cli/pkg/config" + "github.com/supabase/cli/pkg/fetcher" + "github.com/supabase/cli/pkg/storage" +) + +func main() { + if err := seed(context.Background()); err != nil { + log.Fatalln(err) + } +} + +func seed(ctx context.Context) error { + project := os.Getenv("SUPABASE_PROJECT_ID") + serviceRoleKey := os.Getenv("SUPABASE_SERVICE_ROLE_KEY") + storageClient := newStorageClient(project, serviceRoleKey) + public := false + sc := config.BucketConfig{"my-bucket": { + Public: &public, + }} + return storageClient.UpsertBuckets(ctx, sc) +} + +func newStorageClient(project, serviceRoleKey string) storage.StorageAPI { + return storage.StorageAPI{Fetcher: fetcher.NewFetcher( + fmt.Sprintf("https://db.%s.supabase.co", project), + fetcher.WithBearerToken(serviceRoleKey), + fetcher.WithHTTPClient(&http.Client{ + Timeout: time.Second * 10, + }), + fetcher.WithExpectedStatus(http.StatusOK), + )} +} From af171b6ac3147b34f785e5378fd06dea40290ff5 Mon Sep 17 00:00:00 2001 From: Qiao Han Date: Fri, 26 Jul 2024 19:17:00 +0800 Subject: [PATCH 09/14] fix: print config line diff for clarity --- cmd/link.go | 3 -- internal/link/link.go | 102 ++++++++++++++++--------------------- internal/link/link_test.go | 73 ++++---------------------- 3 files changed, 53 insertions(+), 125 deletions(-) diff --git a/cmd/link.go b/cmd/link.go index 780b667e4..b1aec1d7a 100644 --- a/cmd/link.go +++ b/cmd/link.go @@ -36,9 +36,6 @@ var ( } return link.Run(ctx, flags.ProjectRef, fsys) }, - PostRunE: func(cmd *cobra.Command, args []string) error { - return link.PostRun(flags.ProjectRef, os.Stdout, afero.NewOsFs()) - }, } ) diff --git a/internal/link/link.go b/internal/link/link.go index 9d033d47b..b4da42d05 100644 --- a/internal/link/link.go +++ b/internal/link/link.go @@ -1,9 +1,9 @@ package link import ( + "bytes" "context" "fmt" - "io" "os" "strconv" "strings" @@ -11,6 +11,7 @@ import ( "github.com/BurntSushi/toml" "github.com/go-errors/errors" + "github.com/google/go-cmp/cmp" "github.com/jackc/pgconn" "github.com/jackc/pgx/v4" "github.com/spf13/afero" @@ -24,19 +25,11 @@ import ( "github.com/supabase/cli/pkg/migration" ) -var updatedConfig ConfigCopy - -type ConfigCopy struct { - Api interface{} `toml:"api"` - Db interface{} `toml:"db"` - Pooler interface{} `toml:"db.pooler"` -} - -func (c ConfigCopy) IsEmpty() bool { - return c.Api == nil && c.Db == nil && c.Pooler == nil -} - func Run(ctx context.Context, projectRef string, fsys afero.Fs, options ...func(*pgx.ConnConfig)) error { + original := toTomlLines(map[string]interface{}{ + "api": utils.Config.Api, + "db": utils.Config.Db, + }) // 1. Check service config keys, err := tenant.GetApiKeys(ctx, projectRef) if err != nil { @@ -57,21 +50,32 @@ func Run(ctx context.Context, projectRef string, fsys afero.Fs, options ...func( } // 3. Save project ref - return utils.WriteFile(utils.ProjectRefPath, []byte(projectRef), fsys) -} + if err := utils.WriteFile(utils.ProjectRefPath, []byte(projectRef), fsys); err != nil { + return err + } + fmt.Fprintln(os.Stdout, "Finished "+utils.Aqua("supabase link")+".") -func PostRun(projectRef string, stdout io.Writer, fsys afero.Fs) error { - fmt.Fprintln(stdout, "Finished "+utils.Aqua("supabase link")+".") - if updatedConfig.IsEmpty() { - return nil + // 4. Suggest config update + updated := toTomlLines(map[string]interface{}{ + "api": utils.Config.Api, + "db": utils.Config.Db, + }) + lineDiff := cmp.Diff(original, updated) + if len(lineDiff) > 0 { + fmt.Fprintln(os.Stderr, utils.Yellow("WARNING:"), "Local config differs from linked project. Try updating", utils.Bold(utils.ConfigPath)) + fmt.Println(lineDiff) } - fmt.Fprintln(os.Stderr, utils.Yellow("WARNING:"), "Local config differs from linked project. Try updating", utils.Bold(utils.ConfigPath)) - enc := toml.NewEncoder(stdout) + return nil +} + +func toTomlLines(config map[string]interface{}) []string { + var buf bytes.Buffer + enc := toml.NewEncoder(&buf) enc.Indent = "" - if err := enc.Encode(updatedConfig); err != nil { - return errors.Errorf("failed to marshal toml config: %w", err) + if err := enc.Encode(config); err != nil { + fmt.Fprintln(utils.GetDebugLogger(), "failed to marshal toml config:", err) } - return nil + return strings.Split(buf.String(), "\n") } func LinkServices(ctx context.Context, projectRef, anonKey string, fsys afero.Fs) { @@ -139,16 +143,9 @@ func linkPostgrestVersion(ctx context.Context, api tenant.TenantAPI, fsys afero. } func updateApiConfig(config api.PostgrestConfigWithJWTSecretResponse) { - copy := utils.Config.Api - copy.MaxRows = uint(config.MaxRows) - copy.ExtraSearchPath = readCsv(config.DbExtraSearchPath) - copy.Schemas = readCsv(config.DbSchema) - changed := utils.Config.Api.MaxRows != copy.MaxRows || - !utils.SliceEqual(utils.Config.Api.ExtraSearchPath, copy.ExtraSearchPath) || - !utils.SliceEqual(utils.Config.Api.Schemas, copy.Schemas) - if changed { - updatedConfig.Api = copy - } + utils.Config.Api.MaxRows = uint(config.MaxRows) + utils.Config.Api.ExtraSearchPath = readCsv(config.DbExtraSearchPath) + utils.Config.Api.Schemas = readCsv(config.DbSchema) } func readCsv(line string) []string { @@ -205,46 +202,35 @@ func updatePostgresConfig(conn *pgx.Conn) { if majorDigits > 2 { majorDigits = 2 } - dbMajorVersion, err := strconv.ParseUint(serverVersion[:majorDigits], 10, 7) // Treat error as unchanged - if err == nil && uint64(utils.Config.Db.MajorVersion) != dbMajorVersion { - copy := utils.Config.Db - copy.MajorVersion = uint(dbMajorVersion) - updatedConfig.Db = copy + if dbMajorVersion, err := strconv.ParseUint(serverVersion[:majorDigits], 10, 7); err == nil { + utils.Config.Db.MajorVersion = uint(dbMajorVersion) } } func linkPooler(ctx context.Context, projectRef string, fsys afero.Fs) error { - resp, err := utils.GetSupabase().V1GetProjectPgbouncerConfigWithResponse(ctx, projectRef) + resp, err := utils.GetSupabase().V1GetSupavisorConfigWithResponse(ctx, projectRef) if err != nil { return errors.Errorf("failed to get pooler config: %w", err) } if resp.JSON200 == nil { return errors.Errorf("%w: %s", tenant.ErrAuthToken, string(resp.Body)) } - updatePoolerConfig(*resp.JSON200) - if resp.JSON200.ConnectionString != nil { - utils.Config.Db.Pooler.ConnectionString = *resp.JSON200.ConnectionString - return utils.WriteFile(utils.PoolerUrlPath, []byte(utils.Config.Db.Pooler.ConnectionString), fsys) + for _, config := range *resp.JSON200 { + if config.DatabaseType == api.PRIMARY { + updatePoolerConfig(config) + } } - return nil + return utils.WriteFile(utils.PoolerUrlPath, []byte(utils.Config.Db.Pooler.ConnectionString), fsys) } -func updatePoolerConfig(config api.V1PgbouncerConfigResponse) { - copy := utils.Config.Db.Pooler - if config.PoolMode != nil { - copy.PoolMode = cliConfig.PoolMode(*config.PoolMode) - } +func updatePoolerConfig(config api.SupavisorConfigResponse) { + utils.Config.Db.Pooler.ConnectionString = config.ConnectionString + utils.Config.Db.Pooler.PoolMode = cliConfig.PoolMode(config.PoolMode) if config.DefaultPoolSize != nil { - copy.DefaultPoolSize = uint(*config.DefaultPoolSize) + utils.Config.Db.Pooler.DefaultPoolSize = uint(*config.DefaultPoolSize) } if config.MaxClientConn != nil { - copy.MaxClientConn = uint(*config.MaxClientConn) - } - changed := utils.Config.Db.Pooler.PoolMode != copy.PoolMode || - utils.Config.Db.Pooler.DefaultPoolSize != copy.DefaultPoolSize || - utils.Config.Db.Pooler.MaxClientConn != copy.MaxClientConn - if changed { - updatedConfig.Pooler = copy + utils.Config.Db.Pooler.MaxClientConn = uint(*config.MaxClientConn) } } diff --git a/internal/link/link_test.go b/internal/link/link_test.go index a2f63a822..f33961293 100644 --- a/internal/link/link_test.go +++ b/internal/link/link_test.go @@ -3,7 +3,6 @@ package link import ( "context" "errors" - "strings" "testing" "github.com/h2non/gock" @@ -31,42 +30,6 @@ var dbConfig = pgconn.Config{ Database: "postgres", } -// Reset global variable -func teardown() { - updatedConfig.Api = nil - updatedConfig.Db = nil - updatedConfig.Pooler = nil -} - -func TestPostRun(t *testing.T) { - t.Run("prints completion message", func(t *testing.T) { - defer teardown() - project := "test-project" - // Setup in-memory fs - fsys := afero.NewMemMapFs() - // Run test - buf := &strings.Builder{} - err := PostRun(project, buf, fsys) - // Check error - assert.NoError(t, err) - assert.Equal(t, "Finished supabase link.\n", buf.String()) - }) - - t.Run("prints changed config", func(t *testing.T) { - defer teardown() - project := "test-project" - updatedConfig.Api = "test" - // Setup in-memory fs - fsys := afero.NewMemMapFs() - // Run test - buf := &strings.Builder{} - err := PostRun(project, buf, fsys) - // Check error - assert.NoError(t, err) - assert.Contains(t, buf.String(), `api = "test"`) - }) -} - func TestLinkCommand(t *testing.T) { project := "test-project" // Setup valid access token @@ -76,8 +39,7 @@ func TestLinkCommand(t *testing.T) { keyring.MockInit() t.Run("link valid project", func(t *testing.T) { - defer teardown() - defer fstest.MockStdin(t, "\n")() + t.Cleanup(fstest.MockStdin(t, "\n")) // Setup in-memory fs fsys := afero.NewMemMapFs() // Setup mock postgres @@ -96,7 +58,7 @@ func TestLinkCommand(t *testing.T) { Reply(200). JSON(api.V1PostgrestConfigResponse{}) gock.New(utils.DefaultApiHost). - Get("/v1/projects/" + project + "/config/database/pgbouncer"). + Get("/v1/projects/" + project + "/config/database/pooler"). Reply(200). JSON(api.V1PgbouncerConfigResponse{}) // Link versions @@ -152,7 +114,7 @@ func TestLinkCommand(t *testing.T) { }) t.Run("ignores error linking services", func(t *testing.T) { - defer fstest.MockStdin(t, "\n")() + t.Cleanup(fstest.MockStdin(t, "\n")) // Setup in-memory fs fsys := afero.NewMemMapFs() // Flush pending mocks after test execution @@ -166,7 +128,7 @@ func TestLinkCommand(t *testing.T) { Get("/v1/projects/" + project + "/postgrest"). ReplyError(errors.New("network error")) gock.New(utils.DefaultApiHost). - Get("/v1/projects/" + project + "/config/database/pgbouncer"). + Get("/v1/projects/" + project + "/config/database/pooler"). ReplyError(errors.New("network error")) // Link versions gock.New("https://" + utils.GetSupabaseHost(project)). @@ -193,7 +155,6 @@ func TestLinkCommand(t *testing.T) { }) t.Run("throws error on write failure", func(t *testing.T) { - defer teardown() // Setup in-memory fs fsys := afero.NewReadOnlyFs(afero.NewMemMapFs()) // Flush pending mocks after test execution @@ -207,7 +168,7 @@ func TestLinkCommand(t *testing.T) { Get("/v1/projects/" + project + "/postgrest"). ReplyError(errors.New("network error")) gock.New(utils.DefaultApiHost). - Get("/v1/projects/" + project + "/config/database/pgbouncer"). + Get("/v1/projects/" + project + "/config/database/pooler"). ReplyError(errors.New("network error")) // Link versions gock.New("https://" + utils.GetSupabaseHost(project)). @@ -241,7 +202,6 @@ func TestLinkPostgrest(t *testing.T) { t.Setenv("SUPABASE_ACCESS_TOKEN", string(token)) t.Run("ignores matching config", func(t *testing.T) { - defer teardown() // Flush pending mocks after test execution defer gock.OffAll() gock.New(utils.DefaultApiHost). @@ -253,11 +213,9 @@ func TestLinkPostgrest(t *testing.T) { // Check error assert.NoError(t, err) assert.Empty(t, apitest.ListUnmatchedRequests()) - assert.Empty(t, updatedConfig) }) t.Run("updates api on newer config", func(t *testing.T) { - defer teardown() // Flush pending mocks after test execution defer gock.OffAll() gock.New(utils.DefaultApiHost). @@ -273,16 +231,12 @@ func TestLinkPostgrest(t *testing.T) { // Check error assert.NoError(t, err) assert.Empty(t, apitest.ListUnmatchedRequests()) - utils.Config.Api.Schemas = []string{"public", "graphql_public"} - utils.Config.Api.ExtraSearchPath = []string{"public", "extensions"} - utils.Config.Api.MaxRows = 1000 - assert.Equal(t, ConfigCopy{ - Api: utils.Config.Api, - }, updatedConfig) + assert.ElementsMatch(t, []string{"public", "graphql_public"}, utils.Config.Api.Schemas) + assert.ElementsMatch(t, []string{"public", "extensions"}, utils.Config.Api.ExtraSearchPath) + assert.Equal(t, uint(1000), utils.Config.Api.MaxRows) }) t.Run("throws error on network failure", func(t *testing.T) { - defer teardown() // Flush pending mocks after test execution defer gock.OffAll() gock.New(utils.DefaultApiHost). @@ -296,7 +250,6 @@ func TestLinkPostgrest(t *testing.T) { }) t.Run("throws error on server unavailable", func(t *testing.T) { - defer teardown() // Flush pending mocks after test execution defer gock.OffAll() gock.New(utils.DefaultApiHost). @@ -313,16 +266,13 @@ func TestLinkPostgrest(t *testing.T) { func TestLinkDatabase(t *testing.T) { t.Run("throws error on connect failure", func(t *testing.T) { - defer teardown() // Run test err := linkDatabase(context.Background(), pgconn.Config{}) // Check error assert.ErrorContains(t, err, "invalid port (outside range)") - assert.Empty(t, updatedConfig) }) t.Run("ignores missing server version", func(t *testing.T) { - defer teardown() // Setup mock postgres conn := pgtest.NewWithStatus(map[string]string{ "standard_conforming_strings": "on", @@ -333,11 +283,9 @@ func TestLinkDatabase(t *testing.T) { err := linkDatabase(context.Background(), dbConfig, conn.Intercept) // Check error assert.NoError(t, err) - assert.Empty(t, updatedConfig) }) t.Run("updates config to newer db version", func(t *testing.T) { - defer teardown() utils.Config.Db.MajorVersion = 14 // Setup mock postgres conn := pgtest.NewWithStatus(map[string]string{ @@ -351,13 +299,10 @@ func TestLinkDatabase(t *testing.T) { // Check error assert.NoError(t, err) utils.Config.Db.MajorVersion = 15 - assert.Equal(t, ConfigCopy{ - Db: utils.Config.Db, - }, updatedConfig) + assert.Equal(t, uint(15), utils.Config.Db.MajorVersion) }) t.Run("throws error on query failure", func(t *testing.T) { - defer teardown() utils.Config.Db.MajorVersion = 14 // Setup mock postgres conn := pgtest.NewConn() From d1012f4532a35537dffdf078f2cb3418915682f5 Mon Sep 17 00:00:00 2001 From: Qiao Han Date: Fri, 26 Jul 2024 19:18:48 +0800 Subject: [PATCH 10/14] fix: remove unmodifiable api configs --- pkg/config/config.go | 3 --- pkg/config/utils.go | 11 ----------- 2 files changed, 14 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 49fa5fb13..c602f0331 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -636,9 +636,6 @@ func (c *config) Validate() error { if c.Api.Port == 0 { return errors.New("Missing required field in config: api.port") } - // Append required schemas if they are missing - c.Api.Schemas = removeDuplicates(append([]string{"public", "storage"}, c.Api.Schemas...)) - c.Api.ExtraSearchPath = removeDuplicates(append([]string{"public"}, c.Api.ExtraSearchPath...)) } // Validate db config if c.Db.Port == 0 { diff --git a/pkg/config/utils.go b/pkg/config/utils.go index f9962cb68..b2318b5a9 100644 --- a/pkg/config/utils.go +++ b/pkg/config/utils.go @@ -77,17 +77,6 @@ func sliceContains[T comparable](s []T, e T) bool { return false } -func removeDuplicates[T comparable](slice []T) (result []T) { - set := make(map[T]struct{}) - for _, item := range slice { - if _, exists := set[item]; !exists { - set[item] = struct{}{} - result = append(result, item) - } - } - return result -} - func replaceImageTag(image string, tag string) string { index := strings.IndexByte(image, ':') return image[:index+1] + strings.TrimSpace(tag) From 3d925f190b4b3f15aa45e4a2bfdd4dd3e46903c9 Mon Sep 17 00:00:00 2001 From: Qiao Han Date: Fri, 26 Jul 2024 19:19:54 +0800 Subject: [PATCH 11/14] chore: improve test cleanup --- internal/db/push/push_test.go | 2 +- internal/db/reset/reset_test.go | 2 +- internal/logout/logout_test.go | 6 +++--- internal/migration/repair/repair_test.go | 6 +++--- internal/start/start.go | 2 +- internal/storage/rm/rm_test.go | 6 +++--- internal/utils/console_test.go | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/internal/db/push/push_test.go b/internal/db/push/push_test.go index 44d9f024c..e4f6353ec 100644 --- a/internal/db/push/push_test.go +++ b/internal/db/push/push_test.go @@ -128,7 +128,7 @@ func TestPushAll(t *testing.T) { }) t.Run("throws error on cancel", func(t *testing.T) { - defer fstest.MockStdin(t, "n")() + t.Cleanup(fstest.MockStdin(t, "n")) // Setup in-memory fs fsys := afero.NewMemMapFs() path := filepath.Join(utils.MigrationsDir, "0_test.sql") diff --git a/internal/db/reset/reset_test.go b/internal/db/reset/reset_test.go index 90b5ecd77..3c1acd0e3 100644 --- a/internal/db/reset/reset_test.go +++ b/internal/db/reset/reset_test.go @@ -48,7 +48,7 @@ func TestResetCommand(t *testing.T) { }) t.Run("throws error on invalid port", func(t *testing.T) { - defer fstest.MockStdin(t, "y")() + t.Cleanup(fstest.MockStdin(t, "y")) // Setup in-memory fs fsys := afero.NewMemMapFs() // Run test diff --git a/internal/logout/logout_test.go b/internal/logout/logout_test.go index c2bdd2b0d..0bb39be5c 100644 --- a/internal/logout/logout_test.go +++ b/internal/logout/logout_test.go @@ -20,7 +20,7 @@ func TestLogoutCommand(t *testing.T) { t.Run("login with token and logout", func(t *testing.T) { keyring.MockInitWithError(keyring.ErrUnsupportedPlatform) - defer fstest.MockStdin(t, "y")() + t.Cleanup(fstest.MockStdin(t, "y")) // Setup in-memory fs fsys := afero.NewMemMapFs() require.NoError(t, utils.SaveAccessToken(token, fsys)) @@ -49,7 +49,7 @@ func TestLogoutCommand(t *testing.T) { t.Run("exits 0 if not logged in", func(t *testing.T) { keyring.MockInit() - defer fstest.MockStdin(t, "y")() + t.Cleanup(fstest.MockStdin(t, "y")) // Setup in-memory fs fsys := afero.NewMemMapFs() // Run test @@ -60,7 +60,7 @@ func TestLogoutCommand(t *testing.T) { t.Run("throws error on failure to delete", func(t *testing.T) { keyring.MockInitWithError(keyring.ErrNotFound) - defer fstest.MockStdin(t, "y")() + t.Cleanup(fstest.MockStdin(t, "y")) // Setup empty home directory t.Setenv("HOME", "") // Setup in-memory fs diff --git a/internal/migration/repair/repair_test.go b/internal/migration/repair/repair_test.go index a291e5ea9..4dea63279 100644 --- a/internal/migration/repair/repair_test.go +++ b/internal/migration/repair/repair_test.go @@ -98,7 +98,7 @@ func TestRepairCommand(t *testing.T) { func TestRepairAll(t *testing.T) { t.Run("repairs whole history", func(t *testing.T) { - defer fstest.MockStdin(t, "y")() + t.Cleanup(fstest.MockStdin(t, "y")) // Setup in-memory fs fsys := afero.NewMemMapFs() path := filepath.Join(utils.MigrationsDir, "0_test.sql") @@ -119,7 +119,7 @@ func TestRepairAll(t *testing.T) { }) t.Run("reverts whole history", func(t *testing.T) { - defer fstest.MockStdin(t, "y")() + t.Cleanup(fstest.MockStdin(t, "y")) // Setup in-memory fs fsys := afero.NewMemMapFs() // Setup mock postgres @@ -144,7 +144,7 @@ func TestRepairAll(t *testing.T) { }) t.Run("throws error on permission denied", func(t *testing.T) { - defer fstest.MockStdin(t, "y")() + t.Cleanup(fstest.MockStdin(t, "y")) // Setup in-memory fs fsys := &fstest.OpenErrorFs{DenyPath: utils.MigrationsDir} // Run test diff --git a/internal/start/start.go b/internal/start/start.go index 4fd30383d..ade4cc98b 100644 --- a/internal/start/start.go +++ b/internal/start/start.go @@ -34,7 +34,7 @@ import ( ) func suggestUpdateCmd(serviceImages map[string]string) string { - cmd := "You are running outdated service versions locally:\n" + cmd := fmt.Sprintln(utils.Yellow("WARNING:"), "You are running different service versions locally than your linked project:") for k, v := range serviceImages { cmd += fmt.Sprintf("%s => %s\n", k, v) } diff --git a/internal/storage/rm/rm_test.go b/internal/storage/rm/rm_test.go index 4dbe8275a..6032c5b9b 100644 --- a/internal/storage/rm/rm_test.go +++ b/internal/storage/rm/rm_test.go @@ -72,7 +72,7 @@ func TestStorageRM(t *testing.T) { }) t.Run("removes multiple objects", func(t *testing.T) { - defer fstest.MockStdin(t, "y")() + t.Cleanup(fstest.MockStdin(t, "y")) // Setup in-memory fs fsys := afero.NewMemMapFs() // Setup mock api @@ -111,7 +111,7 @@ func TestStorageRM(t *testing.T) { }) t.Run("removes buckets and directories", func(t *testing.T) { - defer fstest.MockStdin(t, "y")() + t.Cleanup(fstest.MockStdin(t, "y")) // Setup in-memory fs fsys := afero.NewMemMapFs() // Setup mock api @@ -181,7 +181,7 @@ func TestStorageRM(t *testing.T) { }) t.Run("throws error on delete failure", func(t *testing.T) { - defer fstest.MockStdin(t, "y")() + t.Cleanup(fstest.MockStdin(t, "y")) // Setup in-memory fs fsys := afero.NewMemMapFs() // Setup mock api diff --git a/internal/utils/console_test.go b/internal/utils/console_test.go index 83dfad8e7..19857ee11 100644 --- a/internal/utils/console_test.go +++ b/internal/utils/console_test.go @@ -22,7 +22,7 @@ func TestPromptYesNo(t *testing.T) { }) t.Run("parses piped stdin", func(t *testing.T) { - defer fstest.MockStdin(t, "y")() + t.Cleanup(fstest.MockStdin(t, "y")) c := NewConsole() // Run test val, err := c.PromptYesNo(context.Background(), "test", false) From 68ca923092a3c9e30534cd16b6ffa97b50b41fb8 Mon Sep 17 00:00:00 2001 From: Qiao Han Date: Sat, 27 Jul 2024 00:52:13 +0800 Subject: [PATCH 12/14] chore: minor style changes --- internal/link/link.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/link/link.go b/internal/link/link.go index b4da42d05..172ea09f7 100644 --- a/internal/link/link.go +++ b/internal/link/link.go @@ -60,15 +60,14 @@ func Run(ctx context.Context, projectRef string, fsys afero.Fs, options ...func( "api": utils.Config.Api, "db": utils.Config.Db, }) - lineDiff := cmp.Diff(original, updated) - if len(lineDiff) > 0 { + if lineDiff := cmp.Diff(original, updated); len(lineDiff) > 0 { fmt.Fprintln(os.Stderr, utils.Yellow("WARNING:"), "Local config differs from linked project. Try updating", utils.Bold(utils.ConfigPath)) fmt.Println(lineDiff) } return nil } -func toTomlLines(config map[string]interface{}) []string { +func toTomlLines(config any) []string { var buf bytes.Buffer enc := toml.NewEncoder(&buf) enc.Indent = "" From d630cf83149635618dd0568110f43795751eec8a Mon Sep 17 00:00:00 2001 From: Qiao Han Date: Sat, 27 Jul 2024 00:54:32 +0800 Subject: [PATCH 13/14] fix: write functions entrypoint to predefined path --- internal/functions/serve/serve.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/functions/serve/serve.go b/internal/functions/serve/serve.go index 290d52ac4..3b6f85119 100644 --- a/internal/functions/serve/serve.go +++ b/internal/functions/serve/serve.go @@ -139,7 +139,7 @@ func ServeFunctions(ctx context.Context, envFilePath string, noVerifyJWT *bool, cmd := append([]string{ "edge-runtime", "start", - "--main-service=.", + "--main-service=/root", fmt.Sprintf("--port=%d", dockerRuntimeServerPort), fmt.Sprintf("--policy=%s", utils.Config.EdgeRuntime.Policy), }, runtimeOption.toArgs()...) @@ -147,7 +147,7 @@ func ServeFunctions(ctx context.Context, envFilePath string, noVerifyJWT *bool, cmd = append(cmd, "--verbose") } cmdString := strings.Join(cmd, " ") - entrypoint := []string{"sh", "-c", `cat <<'EOF' > index.ts && ` + cmdString + ` + entrypoint := []string{"sh", "-c", `cat <<'EOF' > /root/index.ts && ` + cmdString + ` ` + mainFuncEmbed + ` EOF `} From 53d0330babd772e012234169cfa0be74e4290fb9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Jul 2024 04:44:40 +0000 Subject: [PATCH 14/14] chore(deps): bump tar from 7.4.2 to 7.4.3 (#2568) Bumps [tar](https://github.com/isaacs/node-tar) from 7.4.2 to 7.4.3. - [Release notes](https://github.com/isaacs/node-tar/releases) - [Changelog](https://github.com/isaacs/node-tar/blob/main/CHANGELOG.md) - [Commits](https://github.com/isaacs/node-tar/compare/v7.4.2...v7.4.3) --- updated-dependencies: - dependency-name: tar dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c37061378..54a6ae29f 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "bin-links": "^4.0.3", "https-proxy-agent": "^7.0.2", "node-fetch": "^3.3.2", - "tar": "7.4.2" + "tar": "7.4.3" }, "release": { "branches": [