Skip to content

Commit

Permalink
run bazel sync in a repeatable env (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
fenollp authored Apr 7, 2021
1 parent b75d02c commit 44ee481
Show file tree
Hide file tree
Showing 8 changed files with 370 additions and 248 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/snapcraft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ env:
jobs:
build_snap:
name: Build snap on ubuntu
runs-on: ubuntu-latest
runs-on: ubuntu-18.04 # FIXME: https://github.com/samuelmeuli/action-snapcraft/issues/24
steps:
- uses: actions/checkout@v2

Expand Down
27 changes: 23 additions & 4 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,35 @@
on: push
name: Build
on:
push: {}

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BAZELISK_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
bazel-sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- run: DOCKER_BUILDKIT=1 docker build -o=. --target=sync . --progress=plain
- run: git --no-pager diff && [[ 0 -eq $(git --no-pager diff --name-only | wc -l) ]]

build_on_ubuntu:
name: Build on ubuntu
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install
run: sudo apt update && sudo apt-get install -y libgl1-mesa-dev xorg-dev
- run: bazelisk build voidstar
- uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- run: DOCKER_BUILDKIT=1 docker build -o=./bin/ --target=voidstar . --progress=plain
- run: ./bin/voidstar --help


build_on_macos:
name: Build on macos
Expand All @@ -22,6 +40,7 @@ jobs:
python-version: '3.x'
- uses: actions/checkout@v2
- run: bazelisk build voidstar
- run: ./bazel-bin/voidstar/voidstar --help

# build_on_windows: FIXME
# name: Build on windows
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Snap
/snap/.snapcraft
/voidstar_*.snap

/bazelisk

/bin/*
80 changes: 80 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# syntax=docker/dockerfile:1.2

FROM ubuntu:20.04 AS base
WORKDIR /app
ENV DEBIAN_FRONTEND=noninteractive
RUN \
set -ux \
# https://github.com/moby/buildkit/blob/df49b648c8bfef657ba99543390516a3f518d22a/frontend/dockerfile/docs/syntax.md#example-cache-apt-packages
&& rm -f /etc/apt/apt.conf.d/docker-clean \
&& echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' >/etc/apt/apt.conf.d/keep-cache
RUN \
--mount=type=cache,target=/var/cache/apt \
--mount=type=cache,target=/var/lib/apt \
set -ux \
&& apt update \
&& apt install -y --no-install-recommends \
build-essential \
ca-certificates \
curl \
git \
unzip \
tar \
gzip \
python3 \
libgl1-mesa-dev \
xorg-dev \
software-properties-common \
&& update-alternatives --install /usr/bin/python python /usr/bin/python3 1
RUN \
--mount=type=cache,target=/var/cache/apt \
--mount=type=cache,target=/var/lib/apt \
set -ux \
&& add-apt-repository -y ppa:openjdk-r/ppa \
&& apt update \
&& apt install -y --no-install-recommends \
openjdk-8-jdk
ARG BAZEL_VERSION=4.0.0
RUN \
--mount=type=cache,target=/root/.cache/bazel \
set -ux \
&& mkdir /bazel \
&& curl -fsSLo /bazel/installer.sh "https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-installer-linux-x86_64.sh" \
&& curl -fsSLo /bazel/LICENSE.txt "https://raw.githubusercontent.com/bazelbuild/bazel/master/LICENSE" \
&& chmod +x /bazel/installer.sh \
&& /bazel/installer.sh \
&& rm /bazel/installer.sh \
&& bazel version
COPY . .

# sync
FROM base AS sync-then-fmt
RUN \
--mount=type=cache,target=/root/.cache/bazel \
set -ux \
&& bazel sync \
&& grep -v -F \"definition_information\": resolved.bzl >resolved.bzl~ \
&& mv resolved.bzl~ resolved.bzl
RUN \
# Ideally we'd be executing buildifier from within the context of its
# container but it turns out to need a shell:
#17 [sync-fmt 2/2] RUN --mount=from=sync-nofmt,source=/app/resolved.bzl,target=/resolved.bzl,readwrite /buildifier -lint=fix /resolved.bzl
#17 sha256:40d4dd8f67b52312e1515cc06559ee703c9944322416f9aa5c0566f1c541d836
#17 0.441 container_linux.go:367: starting container process caused: exec: "/bin/sh": stat /bin/sh: no such file or directory
#17 ERROR: executor failed running [/bin/sh -c /buildifier -lint=fix /resolved.bzl]: exit code: 1
--mount=from=whilp/buildifier,source=/buildifier,target=/buildifier \
set -ux \
&& /buildifier -lint=fix resolved.bzl
FROM scratch AS sync
COPY --from=sync-then-fmt /app/resolved.bzl /

# voidstar
FROM base AS builder
RUN \
--mount=type=cache,target=/root/.cache/bazel \
set -ux \
&& bazel build voidstar \
# Necessary as COPY --from does not follow symlinks
&& cp /app/bazel-bin/voidstar/voidstar /
FROM scratch AS voidstar
COPY --from=builder /voidstar /
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazel_upgradable",
strip_prefix = "bazel_upgradable-0.2.0",
url = "https://github.com/fenollp/bazel_upgradable/archive/0.2.0.zip",
strip_prefix = "bazel_upgradable-0.2.1",
url = "https://github.com/fenollp/bazel_upgradable/archive/0.2.1.zip",
)

load("@bazel_upgradable//:rule.bzl", "upgradable_repository")
Expand Down
Empty file added bin/.gitkeep
Empty file.
Loading

0 comments on commit 44ee481

Please sign in to comment.