diff --git a/.github/workflows/release.linux_amd64.yml b/.github/workflows/release.linux.yml similarity index 70% rename from .github/workflows/release.linux_amd64.yml rename to .github/workflows/release.linux.yml index e68a842..7429eec 100644 --- a/.github/workflows/release.linux_amd64.yml +++ b/.github/workflows/release.linux.yml @@ -3,10 +3,25 @@ on: types: - created -name: release (linux/amd64) +name: release (linux) jobs: - linux: + build: runs-on: ubuntu-latest + strategy: + matrix: + include: + - arch: amd64 + cc: gcc + - arch: arm64 + cc: aarch64-linux-gnu-gcc + - arch: arm + cc: arm-linux-gnueabihf-gcc + + env: + GOOS: linux + GOARCH: ${{ matrix.arch }} + CC: ${{ matrix.cc }} + steps: - uses: actions/checkout@v2 - uses: actions/setup-go@v2 @@ -16,6 +31,11 @@ jobs: env: GITHUB_TOKEN: ${{ github.token }} + - name: Install cross-compilers + run: | + sudo apt-get update + sudo apt-get install -y gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf + - name: Install nfpm run: | wget https://github.com/goreleaser/nfpm/releases/download/v2.2.3/nfpm_2.2.3_Linux_x86_64.tar.gz @@ -23,14 +43,15 @@ jobs: - name: Build litestream run: | + rm -rf dist mkdir -p dist cp etc/litestream.yml etc/litestream.service dist cat etc/nfpm.yml | LITESTREAM_VERSION=${{ steps.release.outputs.tag_name }} envsubst > dist/nfpm.yml go build -ldflags "-X 'main.Version=${{ steps.release.outputs.tag_name }}'" -o dist/litestream ./cmd/litestream cd dist - tar -czvf litestream-${{ steps.release.outputs.tag_name }}-linux-amd64.tar.gz litestream - ../nfpm pkg --config nfpm.yml --packager deb --target litestream-${{ steps.release.outputs.tag_name }}-linux-amd64.deb + tar -czvf litestream-${{ steps.release.outputs.tag_name }}-${{ env.GOOS }}-${{ env.GOARCH }}.tar.gz litestream + ../nfpm pkg --config nfpm.yml --packager deb --target litestream-${{ steps.release.outputs.tag_name }}-${{ env.GOOS }}-${{ env.GOARCH }}.deb - name: Upload release binary uses: actions/upload-release-asset@v1.0.2 @@ -39,7 +60,7 @@ jobs: with: upload_url: ${{ steps.release.outputs.upload_url }} asset_path: ./dist/litestream - asset_name: litestream-${{ steps.release.outputs.tag_name }}-linux-amd64 + asset_name: litestream-${{ steps.release.outputs.tag_name }}-${{ env.GOOS }}-${{ env.GOARCH }} asset_content_type: application/octet-stream - name: Upload release tarball @@ -48,8 +69,8 @@ jobs: GITHUB_TOKEN: ${{ github.token }} with: upload_url: ${{ steps.release.outputs.upload_url }} - asset_path: ./dist/litestream-${{ steps.release.outputs.tag_name }}-linux-amd64.tar.gz - asset_name: litestream-${{ steps.release.outputs.tag_name }}-linux-amd64.tar.gz + asset_path: ./dist/litestream-${{ steps.release.outputs.tag_name }}-${{ env.GOOS }}-${{ env.GOARCH }}.tar.gz + asset_name: litestream-${{ steps.release.outputs.tag_name }}-${{ env.GOOS }}-${{ env.GOARCH }}.tar.gz asset_content_type: application/gzip - name: Upload debian package @@ -58,6 +79,6 @@ jobs: GITHUB_TOKEN: ${{ github.token }} with: upload_url: ${{ steps.release.outputs.upload_url }} - asset_path: ./dist/litestream-${{ steps.release.outputs.tag_name }}-linux-amd64.deb - asset_name: litestream-${{ steps.release.outputs.tag_name }}-linux-amd64.deb + asset_path: ./dist/litestream-${{ steps.release.outputs.tag_name }}-${{ env.GOOS }}-${{ env.GOARCH }}.deb + asset_name: litestream-${{ steps.release.outputs.tag_name }}-${{ env.GOOS }}-${{ env.GOARCH }}.deb asset_content_type: application/octet-stream diff --git a/.github/workflows/release.linux_amd64_static.yml b/.github/workflows/release.linux_static.yml similarity index 54% rename from .github/workflows/release.linux_amd64_static.yml rename to .github/workflows/release.linux_static.yml index 6043540..a3e4d9d 100644 --- a/.github/workflows/release.linux_amd64_static.yml +++ b/.github/workflows/release.linux_static.yml @@ -3,10 +3,25 @@ on: types: - created -name: release (linux/amd64-static) +name: release (linux/static) jobs: - linux: + build: runs-on: ubuntu-latest + strategy: + matrix: + include: + - arch: amd64 + cc: gcc + - arch: arm64 + cc: aarch64-linux-gnu-gcc + - arch: arm + cc: arm-linux-gnueabihf-gcc + + env: + GOOS: linux + GOARCH: ${{ matrix.arch }} + CC: ${{ matrix.cc }} + steps: - uses: actions/checkout@v2 - uses: actions/setup-go@v2 @@ -16,20 +31,18 @@ jobs: env: GITHUB_TOKEN: ${{ github.token }} - - name: Install nfpm + - name: Install cross-compilers run: | - wget https://github.com/goreleaser/nfpm/releases/download/v2.2.3/nfpm_2.2.3_Linux_x86_64.tar.gz - tar zxvf nfpm_2.2.3_Linux_x86_64.tar.gz + sudo apt-get update + sudo apt-get install -y gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf - name: Build litestream run: | + rm -rf dist mkdir -p dist - cp etc/litestream.yml etc/litestream.service dist - cat etc/nfpm.yml | LITESTREAM_VERSION=${{ steps.release.outputs.tag_name }} envsubst > dist/nfpm.yml go build -ldflags "-w -extldflags "-static" -X 'main.Version=${{ steps.release.outputs.tag_name }}'" -o dist/litestream ./cmd/litestream cd dist - tar -czvf litestream-${{ steps.release.outputs.tag_name }}-linux-amd64-static.tar.gz litestream - ../nfpm pkg --config nfpm.yml --packager deb --target litestream-${{ steps.release.outputs.tag_name }}-linux-amd64-static.deb + tar -czvf litestream-${{ steps.release.outputs.tag_name }}-${{ env.GOOS }}-${{ env.GOARCH }}-static.tar.gz litestream - name: Upload release binary uses: actions/upload-release-asset@v1.0.2 @@ -38,7 +51,7 @@ jobs: with: upload_url: ${{ steps.release.outputs.upload_url }} asset_path: ./dist/litestream - asset_name: litestream-${{ steps.release.outputs.tag_name }}-linux-amd64-static + asset_name: litestream-${{ steps.release.outputs.tag_name }}-${{ env.GOOS }}-${{ env.GOARCH }}-static asset_content_type: application/octet-stream - name: Upload release tarball @@ -47,16 +60,6 @@ jobs: GITHUB_TOKEN: ${{ github.token }} with: upload_url: ${{ steps.release.outputs.upload_url }} - asset_path: ./dist/litestream-${{ steps.release.outputs.tag_name }}-linux-amd64-static.tar.gz - asset_name: litestream-${{ steps.release.outputs.tag_name }}-linux-amd64-static.tar.gz + asset_path: ./dist/litestream-${{ steps.release.outputs.tag_name }}-${{ env.GOOS }}-${{ env.GOARCH }}-static.tar.gz + asset_name: litestream-${{ steps.release.outputs.tag_name }}-${{ env.GOOS }}-${{ env.GOARCH }}-static.tar.gz asset_content_type: application/gzip - - - name: Upload debian package - uses: actions/upload-release-asset@v1.0.2 - env: - GITHUB_TOKEN: ${{ github.token }} - with: - upload_url: ${{ steps.release.outputs.upload_url }} - asset_path: ./dist/litestream-${{ steps.release.outputs.tag_name }}-linux-amd64-static.deb - asset_name: litestream-${{ steps.release.outputs.tag_name }}-linux-amd64-static.deb - asset_content_type: application/octet-stream diff --git a/Makefile b/Makefile index 5200b16..4b4abe5 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,15 @@ default: dist-linux: mkdir -p dist cp etc/litestream.yml dist/litestream.yml - docker run --rm -v "${PWD}":/usr/src/litestream -w /usr/src/litestream -e GOOS=linux -e GOARCH=amd64 golang:1.15 go build -v -o dist/litestream ./cmd/litestream + docker run --rm -v "${PWD}":/usr/src/litestream -w /usr/src/litestream -e GOOS=linux -e GOARCH=amd64 golang:1.16 go build -v -o dist/litestream ./cmd/litestream tar -cz -f dist/litestream-linux-amd64.tar.gz -C dist litestream +dist-linux-arm: + docker run --rm -v "${PWD}":/usr/src/litestream -w /usr/src/litestream -e CGO_ENABLED=1 -e CC=arm-linux-gnueabihf-gcc -e GOOS=linux -e GOARCH=arm golang-xc:1.16 go build -v -o dist/litestream-linux-arm ./cmd/litestream + +dist-linux-arm64: + docker run --rm -v "${PWD}":/usr/src/litestream -w /usr/src/litestream -e CGO_ENABLED=1 -e CC=aarch64-linux-gnu-gcc -e GOOS=linux -e GOARCH=arm64 golang-xc:1.16 go build -v -o dist/litestream-linux-arm64 ./cmd/litestream + dist-macos: ifndef LITESTREAM_VERSION $(error LITESTREAM_VERSION is undefined) diff --git a/db.go b/db.go index 0bc516c..22830df 100644 --- a/db.go +++ b/db.go @@ -1438,9 +1438,9 @@ func RestoreReplica(ctx context.Context, r Replica, opt RestoreOptions) error { // Validate options. if opt.OutputPath == "" { return fmt.Errorf("output path required") - } else if opt.Generation == "" && opt.Index != math.MaxInt64 { + } else if opt.Generation == "" && opt.Index != math.MaxInt32 { return fmt.Errorf("must specify generation when restoring to index") - } else if opt.Index != math.MaxInt64 && !opt.Timestamp.IsZero() { + } else if opt.Index != math.MaxInt32 && !opt.Timestamp.IsZero() { return fmt.Errorf("cannot specify index & timestamp to restore") } @@ -1733,7 +1733,7 @@ type RestoreOptions struct { Generation string // Specific index to restore from. - // Set to math.MaxInt64 to ignore index. + // Set to math.MaxInt32 to ignore index. Index int // Point-in-time to restore database. @@ -1752,7 +1752,7 @@ type RestoreOptions struct { // NewRestoreOptions returns a new instance of RestoreOptions with defaults. func NewRestoreOptions() RestoreOptions { return RestoreOptions{ - Index: math.MaxInt64, + Index: math.MaxInt32, } } diff --git a/etc/nfpm.yml b/etc/nfpm.yml index b86eef5..8352472 100644 --- a/etc/nfpm.yml +++ b/etc/nfpm.yml @@ -1,6 +1,6 @@ name: litestream -arch: amd64 -platform: linux +arch: "${GOARCH}" +platform: "${GOOS}" version: "${LITESTREAM_VERSION}" section: "default" priority: "extra" diff --git a/replica.go b/replica.go index bc24b5a..2b00ade 100644 --- a/replica.go +++ b/replica.go @@ -1109,7 +1109,7 @@ func WALIndexAt(ctx context.Context, r Replica, generation string, maxIndex int, } // If max index is specified but not found, return an error. - if maxIndex != math.MaxInt64 && index != maxIndex { + if maxIndex != math.MaxInt32 && index != maxIndex { return index, fmt.Errorf("unable to locate index %d in generation %q, highest index was %d", maxIndex, generation, index) } return index, nil