Skip to content

Commit

Permalink
Rework build (#2177)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi committed Mar 10, 2023
1 parent 6082cbd commit ee535f5
Show file tree
Hide file tree
Showing 22 changed files with 349 additions and 167 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
@@ -1,6 +1,10 @@
**

!build/version
!cmd
!internal
!go.mod
!go.sum

# so `go build` could set `vcs.revision`, etc.
!.git
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Expand Up @@ -14,7 +14,7 @@ updates:
time: "01:42"

- package-ecosystem: "docker"
directory: "/"
directory: "/build/docker"
labels: ["deps", "no ci"]
open-pull-requests-limit: 20
schedule:
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/docker.yml
Expand Up @@ -95,7 +95,7 @@ jobs:
- name: Initialize Docker Buildx builder
run: bin/task docker-init

- name: Extract Docker image name and tags
- name: Extract Docker image names
id: extract
uses: FerretDB/github-actions/extract-docker-tag@main

Expand All @@ -112,8 +112,13 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build Docker images ${{ steps.extract.outputs.images }} (dev - ${{ steps.extract.outputs.dev }})
run: bin/task docker-push DOCKER_IMAGES=${{ steps.extract.outputs.images }}
- name: Build and push development Docker images ${{ steps.extract.outputs.development_images }}
if: steps.extract.outputs.development_images != ''
run: bin/task docker-development-push DOCKER_IMAGES=${{ steps.extract.outputs.development_images }}

- name: Build and push production Docker images ${{ steps.extract.outputs.production_images }}
if: steps.extract.outputs.production_images != ''
run: bin/task docker-production-push DOCKER_IMAGES=${{ steps.extract.outputs.production_images }}

- name: Check dirty
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Expand Up @@ -90,8 +90,8 @@ jobs:
- name: Regenerate and reformat
run: bin/task gen

- name: Build bin/ferretdb-local
run: bin/task build-local
- name: Build bin/ferretdb
run: bin/task build-host

- name: Wait for and setup environment
run: bin/task env-setup
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/js.yml
Expand Up @@ -51,15 +51,15 @@ jobs:
- name: Run init
run: bin/task init

- name: Build bin/ferretdb-local
run: bin/task build-local
- name: Build bin/ferretdb
run: bin/task build-host

- name: Wait for and setup environment
run: bin/task env-setup

- name: Start FerretDB in the background
run: >
bin/ferretdb-local
bin/ferretdb
--listen-addr=:27017
--proxy-addr=127.0.0.1:47017
--mode=diff-normal
Expand Down
47 changes: 37 additions & 10 deletions .github/workflows/packages.yml
Expand Up @@ -15,6 +15,12 @@ on:
schedule:
- cron: "12 2 * * *"

# Do not run this workflow in parallel for any PR change or branch/tag push
# to save some resources.
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true

env:
GOPATH: /home/runner/go
GOCACHE: /home/runner/go/cache
Expand All @@ -25,9 +31,14 @@ env:
jobs:
build:
name: Build packages
runs-on: ubuntu-22.04
runs-on: faster

if: github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'no ci')
if: >
github.event_name != 'pull_request' ||
(
!contains(github.event.pull_request.labels.*.name, 'no ci') &&
contains(github.event.pull_request.labels.*.name, 'packages')
)
steps:
- name: Checkout code
Expand All @@ -36,6 +47,11 @@ jobs:
fetch-depth: 0 # for `git describe` to work
lfs: false # LFS is used only by website

# for branch.txt on pull_request; `main` is already checked out on push / schedule
- name: Name branch
if: github.event_name == 'pull_request'
run: git checkout -b ${{ github.head_ref }}

- name: Setup Go
uses: FerretDB/github-actions/setup-go@main
with:
Expand All @@ -48,11 +64,14 @@ jobs:
- name: Run init
run: bin/task init

- name: Build release binary
run: bin/task build-release
- name: Setup QEMU
uses: docker/setup-qemu-action@v2

- name: Build packages
run: bin/task packages
- name: Initialize Docker Buildx builder
run: bin/task docker-init

- name: Build production release binary
run: bin/task build-release

- name: Upload ferretdb
uses: actions/upload-artifact@v3
Expand All @@ -62,18 +81,26 @@ jobs:
retention-days: 1
if-no-files-found: error

- name: Upload ferretdb.deb
- name: Build packages
run: bin/task packages

- name: Upload .deb package
uses: actions/upload-artifact@v3
with:
name: ferretdb.deb
path: build/deb/ferretdb.deb
path: tmp/debs/ferretdb.deb
retention-days: 1
if-no-files-found: error

- name: Upload ferretdb.rpm
- name: Upload .rpm package
uses: actions/upload-artifact@v3
with:
name: ferretdb.rpm
path: build/rpm/ferretdb.rpm
path: tmp/rpms/ferretdb.rpm
retention-days: 1
if-no-files-found: error

- name: Check dirty
run: |
git status
git diff --exit-code
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Expand Up @@ -66,9 +66,9 @@ you can reset the environment with `task env-reset`.

You can see all available `task` tasks with `task -l`.

### Building release binary
### Building a production release binary

To build a release binary, run `task build-release`.
To build a production release binary, run `task build-release`.
The result will be saved as `bin/ferretdb`.

## Contributing code
Expand Down
41 changes: 0 additions & 41 deletions Dockerfile

This file was deleted.

7 changes: 4 additions & 3 deletions README.md
Expand Up @@ -89,15 +89,16 @@ For more configuration options check [Configuration flags and variables](https:/
docker run --rm -it --network=ferretdb --entrypoint=mongosh mongo "mongodb://username:password@ferretdb/ferretdb?authMechanism=PLAIN"
```

You can also install with FerretDB with the `.deb` and `.rpm` packages
You can also install FerretDB with the `.deb` and `.rpm` packages or use binaries
provided for each [release](https://github.com/FerretDB/FerretDB/releases).

## Building and packaging

We strongly advise users not to build FerretDB themselves.
Instead, use Docker images or .deb and .rpm packages provided by us.
Instead, use binaries, Docker images, or `.deb`/`.rpm` packages provided by us.

If you want to package FerretDB for your operating system or distribution,
the recommended way is to use the `build-release` task;
the recommended way to build the binary is to use the `build-release` task;
see our [instructions for contributors](CONTRIBUTING.md) for more details.
FerretDB could also be built as any other Go program,
but a few generated files and build tags could affect it.
Expand Down

0 comments on commit ee535f5

Please sign in to comment.