Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(resources): use go generate to download mysql (#782)

qsliu6f43405e2bb3
diff --git a/.gitattributes b/.gitattributes
deleted file mode 100644
index 3c82527589..0000000000
--- a/.gitattributes
+++ /dev/null
@@ -1,2 +0,0 @@
-resources/mysql/mysql-8.0.28-linux-glibc2.17-x86_64-minimal.tar.xz filter=lfs diff=lfs merge=lfs -text
-resources/mysql/mysql-8.0.28-macos11-arm64.tar.gz filter=lfs diff=lfs merge=lfs -text
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index bdbb8684e5..1ab3bf51cf 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -11,6 +11,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
+ - uses: actions/setup-go@v2
+ with:
+ go-version: 1.17
+ - run: go generate ./...
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
@@ -33,10 +37,9 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0
- # lfs: true
- uses: actions/setup-go@v2
with:
go-version: 1.17
- run: |
- # go test -v ./...
- go test $(go list ./... | grep -v /resources/mysql)
+ go generate ./...
+ go test -v ./...
diff --git a/resources/README.md b/resources/README.md
index a93489e003..ff944c2704 100644
--- a/resources/README.md
+++ b/resources/README.md
@@ -1,5 +1,7 @@
# Resources
+You need to run `go generate ./...` to download some resources manually.
+
## Postgresql
We will embed Postgres binaries to serve and store backend data. We will extract the binary to a binary path and install Postgres. We will use Go file suffix build tags to include the embedded file only for the build platform. For example, resources_darwin.go will only be included for building Bytebase on darwin platform. However, we will also use build tag `alpine` to differentiate builds on Linux and alpine Linux. We have to include alpine Linux because its underlying libc is different from regular Linux, and we use alpine Linux for our docker images.
@@ -9,3 +11,11 @@ linux/amd64 used for Linux (MD5 3b5b460450f09543f1055e7ffd1cf773): https://repo1
linux/amd64 used for Alpine Linux - Docker image (MD5 2f7e10b17683bcbcba264057d7c4215d): https://repo1.maven.org/maven2/io/zonky/test/postgres/embedded-postgres-binaries-linux-amd64-alpine/14.2.0/embedded-postgres-binaries-linux-amd64-alpine-14.2.0.jar
darwin/amd64 used for MacOS development (MD5 d95d5c5fccc1e1ef45de6533fd8e6d0a): https://repo1.maven.org/maven2/io/zonky/test/postgres/embedded-postgres-binaries-darwin-amd64/14.2.0/embedded-postgres-binaries-darwin-amd64-14.2.0.jar
+
+## MySQL
+
+We will embed MySQL binaries for testing. You need to run `go generate ./...` to download MySQL distributions first.
+
+linux-glibc2.17-x86_64 used for Linux (MD5 55a7759e25cc527416150c8181ce3f6d): https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.28-linux-glibc2.17-x86_64-minimal.tar.xz
+
+macos11-arm64 used for MacOS Apple Silicon development (MD5 f1943053b12428e4c0e4ed309a636fd0): https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.28-macos11-arm64.tar.gz
diff --git a/resources/mysql/fetch_mysql.sh b/resources/mysql/fetch_mysql.sh
new file mode 100755
index 0000000000..95eba15f8f
--- /dev/null
+++ b/resources/mysql/fetch_mysql.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+ckmd5() {
+ if [[ $(uname) = Darwin ]]; then
+ test $(md5 -q $1) = $2
+ else
+ test $(md5sum $1 | awk '{ print $1 }') = $2
+ fi
+}
+
+atomic_download() {
+ if [[ ! -e $1 ]]; then
+ echo "Downloading $1..."
+ curl -o $1.tmp https://cdn.mysql.com//Downloads/MySQL-8.0/$1
+ if $(ckmd5 $1.tmp $2); then
+ mv $1.tmp $1
+ else
+ rm $1.tmp
+ fi
+ fi
+}
+
+mysql_8_0_28_macos11_arm64() {
+ if [[ $(uname) = Darwin && $(uname -m) = arm64 ]]; then
+ atomic_download mysql-8.0.28-macos11-arm64.tar.gz f1943053b12428e4c0e4ed309a636fd0
+ else
+ touch mysql-8.0.28-macos11-arm64.tar.gz
+ fi
+}
+
+mysql_8_0_28_linux_glibc2_17_x86_64_minimal() {
+ if [[ ! $(uname) = Darwin || ! $(uname -m) = arm64 ]]; then
+ atomic_download mysql-8.0.28-linux-glibc2.17-x86_64-minimal.tar.xz 55a7759e25cc527416150c8181ce3f6d
+ else
+ touch mysql-8.0.28-linux-glibc2.17-x86_64-minimal.tar.xz
+ fi
+}
+
+mysql() {
+ mysql_8_0_28_macos11_arm64
+ mysql_8_0_28_linux_glibc2_17_x86_64_minimal
+}
+
+mysql
diff --git a/resources/mysql/mysql-8.0.28-linux-glibc2.17-x86_64-minimal.tar.xz b/resources/mysql/mysql-8.0.28-linux-glibc2.17-x86_64-minimal.tar.xz
deleted file mode 100644
index 70aa85d87a..0000000000
--- a/resources/mysql/mysql-8.0.28-linux-glibc2.17-x86_64-minimal.tar.xz
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:39d58319a2d34b27dc229eb32c07f3902863fb5dfe25d25b5d537cc7299b4fed
-size 54089904
diff --git a/resources/mysql/mysql.go b/resources/mysql/mysql.go
index ffa4fc4e26..f37b0a00a9 100644
--- a/resources/mysql/mysql.go
+++ b/resources/mysql/mysql.go
@@ -17,7 +17,11 @@ import (
_ "github.com/go-sql-driver/mysql"
)
+//go:generate ./fetch_mysql.sh
+
//go:embed mysql-8.0.28-macos11-arm64.tar.gz mysql-8.0.28-linux-glibc2.17-x86_64-minimal.tar.xz
+// To use this package in testing, download the MySQL binary first:
+// go generate ./...
var resources embed.FS
// Instance is MySQL instance installed by bytebase for testing.