From fafa9aabc4fe762ebc18ec48f0aed074af0d0da8 Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Mon, 25 Jul 2022 17:34:16 +0300 Subject: [PATCH] Build packages on CI (#938) Closes #902. --- .github/RELEASE_CHECKLIST.md | 19 +++--- .github/workflows/packages.yml | 65 +++++++++++++++++++ .gitignore | 11 ++++ .nfpm.yml | 14 ---- README.md | 5 +- Taskfile.yml | 38 +++++++---- build/deb/.gitkeep | 0 build/deps/centos7.Dockerfile | 1 + build/deps/debian11.Dockerfile | 1 + .../{mongo.Dockerfile => mongo5.Dockerfile} | 0 build/nfpm.yaml | 16 +++++ build/rpm/.gitkeep | 0 docker-compose.yml | 18 ++++- 13 files changed, 149 insertions(+), 39 deletions(-) create mode 100644 .github/workflows/packages.yml delete mode 100644 .nfpm.yml create mode 100644 build/deb/.gitkeep create mode 100644 build/deps/centos7.Dockerfile create mode 100644 build/deps/debian11.Dockerfile rename build/deps/{mongo.Dockerfile => mongo5.Dockerfile} (100%) create mode 100644 build/nfpm.yaml create mode 100644 build/rpm/.gitkeep diff --git a/.github/RELEASE_CHECKLIST.md b/.github/RELEASE_CHECKLIST.md index 99400ba48614..1ef74b76036e 100644 --- a/.github/RELEASE_CHECKLIST.md +++ b/.github/RELEASE_CHECKLIST.md @@ -12,16 +12,17 @@ 6. Make a signed tag `vX.Y.Z` with the relevant section of the changelog using `--cleanup=verbatim`. 7. Push it! 8. Make [release](https://github.com/FerretDB/FerretDB/releases). -9. Refresh - * `env GOPROXY=https://proxy.golang.org go install -v github.com/FerretDB/FerretDB/cmd/ferretdb@` - * `env GOPROXY=https://proxy.golang.org go install -v github.com/FerretDB/FerretDB/ferretdb@` - (expected error message is `package github.com/FerretDB/FerretDB/ferretdb is not a main package`) - * -10. `task docker-local` -11. `task docker-push` with four tags (`X.Y.Z` without leading `v` and `latest` for both ghcr.io and Docker Hub): +9. Upload .deb and .rpm packages from the CI build for the tag. +10. Refresh + * `env GOPROXY=https://proxy.golang.org go install -v github.com/FerretDB/FerretDB/cmd/ferretdb@` + * `env GOPROXY=https://proxy.golang.org go install -v github.com/FerretDB/FerretDB/ferretdb@` + (expected error message is `package github.com/FerretDB/FerretDB/ferretdb is not a main package`) + * +11. `task docker-local` +12. `task docker-push` with four tags (`X.Y.Z` without leading `v` and `latest` for both ghcr.io and Docker Hub): * `task docker-push DOCKER_IMAGE=ferretdb/ferretdb:latest` * `task docker-push DOCKER_IMAGE=ferretdb/ferretdb:` * `task docker-push DOCKER_IMAGE=ghcr.io/ferretdb/ferretdb:latest` * `task docker-push DOCKER_IMAGE=ghcr.io/ferretdb/ferretdb:` -12. Close milestone in issues. -13. Announce it! +13. Close milestone in issues. +14. Announce it! diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.yml new file mode 100644 index 000000000000..77707294ac04 --- /dev/null +++ b/.github/workflows/packages.yml @@ -0,0 +1,65 @@ +--- +name: Packages +on: + pull_request: + types: + - unlabeled # if GitHub Actions stuck, add and remove "no ci" label to force rebuild + - opened + - reopened + - synchronize + push: + branches: + - main + tags: + - "*" + schedule: + - cron: "12 2 * * *" + +env: + GOPATH: /home/runner/go + GOCACHE: /home/runner/go/cache + GOLANGCI_LINT_CACHE: /home/runner/go/cache/lint + GOMODCACHE: /home/runner/go/mod + GOPROXY: https://proxy.golang.org + +jobs: + build: + name: Build + runs-on: ubuntu-20.04 + + if: github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'no ci') + + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Setup Go + uses: FerretDB/github-actions/setup-go@main + with: + cache-key: packages + + - name: Install Task + run: go generate -x + working-directory: tools + + - name: Run init + run: bin/task init + + - name: Build packages + run: bin/task packages + + - name: Upload ferretdb.deb + uses: actions/upload-artifact@v3 + with: + name: ferretdb.deb + path: build/deb/ferretdb.deb + if-no-files-found: error + + - name: Upload ferretdb.rpm + uses: actions/upload-artifact@v3 + with: + name: ferretdb.rpm + path: build/rpm/ferretdb.rpm + if-no-files-found: error diff --git a/.gitignore b/.gitignore index 7f61fb26ff66..222d6ea86ddf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,19 @@ # Please use global .gitignore file for .vscode/, .idea/, etc. # See https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files#configuring-ignored-files-for-all-repositories-on-your-computer +# out tools bin/ + +# temporary `go mod vendor` directory vendor/ +# task cache +.task/ + +# packages +*.deb +*.rpm + # test coverage results, generated files like commit.txt, etc. *.txt @@ -13,4 +23,5 @@ vendor/ # for now testdata/fuzz/ +# for local Docker Compse changes; see https://docs.docker.com/compose/extends/#multiple-compose-files docker-compose.override.yml diff --git a/.nfpm.yml b/.nfpm.yml deleted file mode 100644 index 2e2c49a7323b..000000000000 --- a/.nfpm.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -name: "ferretdb" -arch: "amd64" -platform: "linux" -version: "${VERSION}" -section: "database" -priority: "extra" -maintainer: FerretDB -description: "it is an open source proxy,which converts MongoDB 5.0+ wire protocol queries to SQL using PostgreSQL as the database engine." -homepage: "http://ferretdb.com" -license: Apache License 2 -contents: - - src: ../../bin/ferretdb-testcover - dst: /usr/bin/ferretdb diff --git a/README.md b/README.md index a6c70d9bd3f8..e6e32cbf8c80 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,7 @@ and [contributing guidelines](CONTRIBUTING.md). ### Known differences 1. FerretDB uses the same protocol error names and codes, but the exact error messages may be different in some cases. - 2. FerretDB does not support NUL (`\0`) characters in strings. - 3. Database and collection names restrictions: * name cannot start with the reserved prefix `_ferretdb_`. @@ -103,6 +101,9 @@ docker run --rm -it --network=ferretdb --entrypoint=mongosh mongo:5 mongodb://fe +You can also install with FerretDB with the `.deb` and `.rpm` packages +provided for each [release](https://github.com/FerretDB/FerretDB/releases). + ## Community * Website and blog: [https://ferretdb.io](https://ferretdb.io/). diff --git a/Taskfile.yml b/Taskfile.yml index c1d06ccd9a97..3e04d358f081 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -24,6 +24,7 @@ tasks: - task: docs gen-version: + run: once cmds: - go generate -x ./internal/util/version @@ -186,6 +187,7 @@ tasks: build-testcover: desc: "Build bin/ferretdb-testcover" + run: once deps: [gen-version] cmds: - go test -c -o=bin/ferretdb-testcover{{exeExt}} -trimpath -tags=ferretdb_testcover,ferretdb_tigris {{if ne OS "windows"}}-race{{end}} -coverpkg=./... ./cmd/ferretdb @@ -293,25 +295,35 @@ tasks: COMMIT: sh: cat internal/util/version/gen/commit.txt - nfpm_deb: + packages: + cmds: + - task: packages-deb + - task: packages-rpm + + packages-deb: deps: [build-testcover] - dir: build/deb + dir: build cmds: - - ../../bin/nfpm pkg --config ../../.nfpm.yml --packager deb --target ferretdb_${VERSION}.deb + - ../bin/nfpm{{exeExt}} package --packager=deb --target=deb/ferretdb.deb + - > + docker-compose run --rm debian /bin/sh -c + 'dpkg -i /deb/ferretdb.deb && ferretdb -version' env: VERSION: - sh: cat ../../internal/util/version/gen/version.txt + sh: cat ../internal/util/version/gen/version.txt + GOARCH: + sh: go env GOARCH - nfpm_rpm: + packages-rpm: deps: [build-testcover] - dir: build/rpm + dir: build cmds: - - ../../bin/nfpm pkg --config ../../.nfpm.yml --packager rpm --target ferretdb_${VERSION}.rpm + - ../bin/nfpm{{exeExt}} package --packager=rpm --target=rpm/ferretdb.rpm + - > + docker-compose run --rm centos /bin/sh -c + 'rpm -i /rpm/ferretdb.rpm && ferretdb -version' env: VERSION: - sh: cat ../../internal/util/version/gen/version.txt - - packager: - cmds: - - task: nfpm_deb - - task: nfpm_rpm + sh: cat ../internal/util/version/gen/version.txt + GOARCH: + sh: go env GOARCH diff --git a/build/deb/.gitkeep b/build/deb/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/build/deps/centos7.Dockerfile b/build/deps/centos7.Dockerfile new file mode 100644 index 000000000000..0bc84823c83e --- /dev/null +++ b/build/deps/centos7.Dockerfile @@ -0,0 +1 @@ +FROM centos:7.9.2009 diff --git a/build/deps/debian11.Dockerfile b/build/deps/debian11.Dockerfile new file mode 100644 index 000000000000..c34cf323379e --- /dev/null +++ b/build/deps/debian11.Dockerfile @@ -0,0 +1 @@ +FROM debian:11.4 diff --git a/build/deps/mongo.Dockerfile b/build/deps/mongo5.Dockerfile similarity index 100% rename from build/deps/mongo.Dockerfile rename to build/deps/mongo5.Dockerfile diff --git a/build/nfpm.yaml b/build/nfpm.yaml new file mode 100644 index 000000000000..7637eaebdeab --- /dev/null +++ b/build/nfpm.yaml @@ -0,0 +1,16 @@ +--- +name: ferretdb +arch: ${GOARCH} +platform: linux +version: ${VERSION} +section: database +maintainer: FerretDB packages +description: > + FerretDB (previously MangoDB) was founded to become the de-facto open-source substitute to MongoDB. + FerretDB is an open-source proxy, converting the MongoDB 5.0+ wire protocol queries to SQL - + using PostgreSQL as a database engine. +homepage: https://ferretdb.io +license: Apache License 2.0 +contents: + - src: ../bin/ferretdb-testcover + dst: /usr/bin/ferretdb diff --git a/build/rpm/.gitkeep b/build/rpm/.gitkeep new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/docker-compose.yml b/docker-compose.yml index 2732b1d0b006..f285b79a87bc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -31,7 +31,7 @@ services: mongodb: build: context: ./build/deps - dockerfile: mongo.Dockerfile + dockerfile: ${MONGO_DOCKERFILE:-mongo5}.Dockerfile container_name: ferretdb_mongodb command: --enableFreeMonitoring off ports: @@ -49,3 +49,19 @@ services: container_name: ferretdb_markdownlint volumes: - .:/workdir + + debian: + build: + context: ./build/deps + dockerfile: debian11.Dockerfile + container_name: ferretdb_debian + volumes: + - ./build/deb:/deb + + centos: + build: + context: ./build/deps + dockerfile: centos7.Dockerfile + container_name: ferretdb_centos + volumes: + - ./build/rpm:/rpm