Skip to content

Commit

Permalink
Implement bake preview builds
Browse files Browse the repository at this point in the history
  • Loading branch information
ianpittwood committed Apr 8, 2024
1 parent 68e44ba commit 7df68cb
Show file tree
Hide file tree
Showing 5 changed files with 768 additions and 4 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/build-bake-preview.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
on:
schedule:
- cron: '0 8 * * *'
- cron: '0 9 * * *'
push:
branches:
- main
- dev
- dev-rspm
pull_request:

name: Preview - Build, Test, and Push
jobs:
build-preview:
runs-on: ubuntu-latest-4x

concurrency:
group: bake-preview-${{ github.ref }}
cancel-in-progress: true

steps:
- name: Check Out main Branch
if: github.event.schedule == '0 8 * * *'
uses: actions/checkout@v3
with:
ref: 'main'

- name: Check Out Repo at Triggered Branch
if: github.event.schedule != '0 8 * * *'
uses: actions/checkout@v3

- name: Set up Just
uses: extractions/setup-just@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Get Version
id: get-version
run: |
WORKBENCH_DAILY_VERSION=$(just -f ci.Justfile get-version workbench --type=daily --local)
echo "WORKBENCH_DAILY_VERSION=$WORKBENCH_DAILY_VERSION" >> $GITHUB_OUTPUT
WORKBENCH_PREVIEW_VERSION=$(just -f ci.Justfile get-version workbench --type=preview --local)
echo "WORKBENCH_PREVIEW_VERSION=$WORKBENCH_PREVIEW_VERSION" >> $GITHUB_OUTPUT
PACKAGE_MANAGER_DAILY_VERSION=$(just -f ci.Justfile get-version package-manager --type=daily --local)
echo "PACKAGE_MANAGER_DAILY_VERSION=$PACKAGE_MANAGER_DAILY_VERSION" >> $GITHUB_OUTPUT
CONNECT_DAILY_VERSION=$(just -f ci.Justfile get-version connect --type=daily --local)
echo "CONNECT_DAILY_VERSION=$CONNECT_DAILY_VERSION" >> $GITHUB_OUTPUT
- name: Build and test
id: build
uses: docker/bake-action@v4
env:
WORKBENCH_DAILY_VERSION: ${{ steps.get-version.outputs.WORKBENCH_DAILY_VERSION }}
WORKBENCH_PREVIEW_VERSION: ${{ steps.get-version.outputs.WORKBENCH_PREVIEW_VERSION }}
PACKAGE_MANAGER_DAILY_VERSION: ${{ steps.get-version.outputs.PACKAGE_MANAGER_DAILY_VERSION }}
CONNECT_DAILY_VERSION: ${{ steps.get-version.outputs.CONNECT_DAILY_VERSION }}
BRANCH: ${{ github.head_ref || github.ref_name }}
with:
set: |
*.cache-from=type=gha
*.cache-to=type=gha,compression=zstd
targets: "build-test"
push: false

- name: Test Connect (privileged container)
run: |
just -f build.justfile test-connect-preview
- name: Push
id: push
if: github.ref == 'refs/heads/main'
uses: docker/bake-action@v4
with:
set: |
*.cache-from=type=gha
*.cache-to=type=gha,compression=zstd
targets: "build"
push: true

63 changes: 63 additions & 0 deletions build.justfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,68 @@ bake target:
just -f {{justfile()}} create-builder || true
docker buildx bake --builder=posit-builder -f docker-bake.hcl {{target}}

preview-bake target branch="$(git branch --show-current)":
just -f {{justfile()}} create-builder || true
WORKBENCH_DAILY_VERSION=$(just -f ci.Justfile get-version workbench --type=daily --local) \
WORKBENCH_PREVIEW_VERSION=$(just -f ci.Justfile get-version workbench --type=preview --local) \
PACKAGE_MANAGER_DAILY_VERSION=$(just -f ci.Justfile get-version package-manager --type=daily --local) \
CONNECT_DAILY_VERSION=$(just -f ci.Justfile get-version connect --type=daily --local) \
BRANCH="{{branch}}" \
docker buildx bake --builder=posit-builder -f docker-bake.preview.hcl {{target}}

# just plan
plan:
docker buildx bake -f docker-bake.hcl --print

preview-plan branch="$(git branch --show-current)":
WORKBENCH_DAILY_VERSION=$(just -f ci.Justfile get-version workbench --type=daily --local) \
WORKBENCH_PREVIEW_VERSION=$(just -f ci.Justfile get-version workbench --type=preview --local) \
PACKAGE_MANAGER_DAILY_VERSION=$(just -f ci.Justfile get-version package-manager --type=daily --local) \
CONNECT_DAILY_VERSION=$(just -f ci.Justfile get-version connect --type=daily --local) \
BRANCH="{{branch}}" \
docker buildx bake -f docker-bake.preview.hcl --print

# just build
build:
just -f {{justfile()}} bake build

preview-build branch="$(git branch --show-current)":
WORKBENCH_DAILY_VERSION=$(just -f ci.Justfile get-version workbench --type=daily --local) \
WORKBENCH_PREVIEW_VERSION=$(just -f ci.Justfile get-version workbench --type=preview --local) \
PACKAGE_MANAGER_DAILY_VERSION=$(just -f ci.Justfile get-version package-manager --type=daily --local) \
CONNECT_DAILY_VERSION=$(just -f ci.Justfile get-version connect --type=daily --local) \
BRANCH="{{branch}}" \
just -f {{justfile()}} bake preview-build

# just test
test:
just -f {{justfile()}} bake test
just -f {{justfile()}} test-connect ubuntu2204

# just preview-test
preview-test branch="$(git branch --show-current)":
WORKBENCH_DAILY_VERSION=$(just -f ci.Justfile get-version workbench --type=daily --local) \
WORKBENCH_PREVIEW_VERSION=$(just -f ci.Justfile get-version workbench --type=preview --local) \
PACKAGE_MANAGER_DAILY_VERSION=$(just -f ci.Justfile get-version package-manager --type=daily --local) \
CONNECT_DAILY_VERSION=$(just -f ci.Justfile get-version connect --type=daily --local) \
BRANCH="{{branch}}" \
just -f {{justfile()}} bake preview-test
WORKBENCH_DAILY_VERSION=$(just -f ci.Justfile get-version workbench --type=daily --local) \
WORKBENCH_PREVIEW_VERSION=$(just -f ci.Justfile get-version workbench --type=preview --local) \
PACKAGE_MANAGER_DAILY_VERSION=$(just -f ci.Justfile get-version package-manager --type=daily --local) \
CONNECT_DAILY_VERSION=$(just -f ci.Justfile get-version connect --type=daily --local) \
BRANCH="{{branch}}" \
just -f {{justfile()}} test-connect-preview ubuntu2204

# just build-test
build-test:
just -f {{justfile()}} build
just -f {{justfile()}} test

preview-build-test:
just -f {{justfile()}} preview-build
just -f {{justfile()}} preview-test

# Run tests

# just test-connect ubuntu2204
Expand All @@ -51,3 +95,22 @@ test-connect os="ubuntu2204":
exit 1
fi
bash -c "$build_cmd"

# just test-connect ubuntu2204
test-connect-preview os="ubuntu2204":
#!/bin/bash
set -x
just -f {{justfile()}} create-builder || true
build_cmd=$( \
WORKBENCH_DAILY_VERSION=$(just -f ci.Justfile get-version workbench --type=daily --local) \
WORKBENCH_PREVIEW_VERSION=$(just -f ci.Justfile get-version workbench --type=preview --local) \
PACKAGE_MANAGER_DAILY_VERSION=$(just -f ci.Justfile get-version package-manager --type=daily --local) \
CONNECT_DAILY_VERSION=$(just -f ci.Justfile get-version connect --type=daily --local) \
python3 {{justfile_directory()}}/tools/bake_test_command_extract.py connect-daily {{os}} --file "docker-bake.preview.hcl" \
)
echo $build_cmd
if [[ $? -ne 0 ]]; then
echo "Failed to extract build command"
exit 1
fi
bash -c "$build_cmd"
2 changes: 1 addition & 1 deletion docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ target "package-manager" {
target = "build"

name = "package-manager-${builds.os}-${replace(PACKAGE_MANAGER_VERSION, ".", "-")}"
tags = get_tags(builds.os, "package-manager", PACKAGE_MANAGER_VERSION)
tags = get_tags(builds.os, "rstudio-package-manager", PACKAGE_MANAGER_VERSION)

dockerfile = "Dockerfile.${builds.os}"
context = "package-manager"
Expand Down
Loading

0 comments on commit 7df68cb

Please sign in to comment.