From d38762bd8fdc2608b13e502eaaf7fc5d17462898 Mon Sep 17 00:00:00 2001 From: eitsupi Date: Mon, 6 Mar 2023 13:22:59 +0900 Subject: [PATCH 1/2] build: add definitions for devcontainer base image --- .devcontainer/base-image/Dockerfile | 15 +++++++ .github/dependabot.yml | 7 ++++ .github/workflows/devcontainer.yaml | 63 +++++++++++++++++++++++++++++ Taskfile.yml | 11 +++++ 4 files changed, 96 insertions(+) create mode 100644 .devcontainer/base-image/Dockerfile create mode 100644 .github/workflows/devcontainer.yaml diff --git a/.devcontainer/base-image/Dockerfile b/.devcontainer/base-image/Dockerfile new file mode 100644 index 000000000000..72b1186425a7 --- /dev/null +++ b/.devcontainer/base-image/Dockerfile @@ -0,0 +1,15 @@ +FROM mcr.microsoft.com/devcontainers/rust:0.203.7-1 + +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + cmake \ + && rm -rf /var/lib/apt/lists/* \ + && sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin + +# ========= Install cargo-tools for non-root user (vscode) ========= +COPY Taskfile.yml /tmp/Taskfile.yml +WORKDIR /tmp +USER vscode +RUN task install-cargo-tools + +USER root diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 9037733798b9..cf0f85edf82a 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -29,6 +29,13 @@ updates: commit-message: prefix: "chore: " + - package-ecosystem: docker + directory: .devcontainer/base-image + schedule: + interval: daily + commit-message: + prefix: "chore: " + # For actions (rather than workflows), we need to list each directory, ref # https://github.com/dependabot/dependabot-core/issues/5137, from https://github.com/dependabot/dependabot-core/issues/4178#issuecomment-1118492006 - directory: ".github/actions/build-prql-js" diff --git a/.github/workflows/devcontainer.yaml b/.github/workflows/devcontainer.yaml new file mode 100644 index 000000000000..25e3fd2c71b1 --- /dev/null +++ b/.github/workflows/devcontainer.yaml @@ -0,0 +1,63 @@ +name: devcontainer + +on: + push: + # ToDo: Add partial Taskfile (only include rust-tools) + paths: + - .devcontainer/base-image/Dockerfile + pull_request: + paths: + - .devcontainer/base-image/Dockerfile + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: docker/metadata-action@v4 + id: meta + with: + images: ghcr.io/${{ github.repository_owner }}/prql-devcontainer-base + tags: | + type=raw,latest + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - id: set-platforms + run: | + if [ "${{ github.ref }}" = "refs/heads/main" ]; then + echo "platforms=linux/amd64,linux/arm64" >>$GITHUB_OUTPUT + echo "push=true" >>$GITHUB_OUTPUT + else + echo "platforms=linux/amd64" >>$GITHUB_OUTPUT + echo "push=false" >>$GITHUB_OUTPUT + fi + + - name: Build + uses: docker/build-push-action@v4 + with: + file: "./.devcontainer/base-image/Dockerfile" + tags: ${{ steps.meta.outputs.tags }} + platforms: ${{ steps.set-platforms.outputs.platforms }} + push: ${{ steps.set-platforms.outputs.push }} + cache-from: | + ${{ env.IMAGE_NAME }} + type=gha + cache-to: | + type=inline + type=gha,mode=max diff --git a/Taskfile.yml b/Taskfile.yml index 0407891f50f6..727f2a3220fb 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -52,6 +52,17 @@ tasks: 🟢 Setup complete! ✅🚀" silent: true + setup-devcontainer: + desc: Install tools for PRQL development (Rust, JS, Python). + cmds: + - task: install-maturin + - task: install-npm-dependencies + - task: install-cargo-tools + - cmd: | + echo " + 🟢 Setup complete! ✅🚀" + silent: true + install-cargo-tools: # factored this out because it takes a long time to build desc: Install cargo tools for PRQL development. From 4ed8d2361606ad81b6101441a5df22ef758a1e43 Mon Sep 17 00:00:00 2001 From: eitsupi Date: Mon, 6 Mar 2023 13:58:44 +0900 Subject: [PATCH 2/2] build: split install-cargo-tools task to another Taskfile --- .devcontainer/base-image/Dockerfile | 4 ++-- .github/workflows/devcontainer.yaml | 3 ++- Taskfile.cargo-tools.yml | 19 ++++++++++++++++++ Taskfile.yml | 31 +++++++---------------------- 4 files changed, 30 insertions(+), 27 deletions(-) create mode 100644 Taskfile.cargo-tools.yml diff --git a/.devcontainer/base-image/Dockerfile b/.devcontainer/base-image/Dockerfile index 72b1186425a7..00200fe5b006 100644 --- a/.devcontainer/base-image/Dockerfile +++ b/.devcontainer/base-image/Dockerfile @@ -7,9 +7,9 @@ RUN apt-get update \ && sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin # ========= Install cargo-tools for non-root user (vscode) ========= -COPY Taskfile.yml /tmp/Taskfile.yml +COPY Taskfile.cargo-tools.yml /tmp/Taskfile.cargo-tools.yml WORKDIR /tmp USER vscode -RUN task install-cargo-tools +RUN task -t Taskfile.cargo-tools.yml install USER root diff --git a/.github/workflows/devcontainer.yaml b/.github/workflows/devcontainer.yaml index 25e3fd2c71b1..1b28019a4975 100644 --- a/.github/workflows/devcontainer.yaml +++ b/.github/workflows/devcontainer.yaml @@ -2,12 +2,13 @@ name: devcontainer on: push: - # ToDo: Add partial Taskfile (only include rust-tools) paths: - .devcontainer/base-image/Dockerfile + - Taskfile.cargo-tools.yml pull_request: paths: - .devcontainer/base-image/Dockerfile + - Taskfile.cargo-tools.yml workflow_dispatch: concurrency: diff --git a/Taskfile.cargo-tools.yml b/Taskfile.cargo-tools.yml new file mode 100644 index 000000000000..814e4108fece --- /dev/null +++ b/Taskfile.cargo-tools.yml @@ -0,0 +1,19 @@ +# yaml-language-server: $schema=https://json.schemastore.org/taskfile.json + +version: 3 + +tasks: + install: + # factored this out because it takes a long time to build + desc: Install cargo tools for PRQL development. + cmds: + # `--locked` installs from the underlying lock files (which is not the + # default?!) + - cargo install --locked bacon cargo-audit cargo-insta cargo-release + default-target mdbook mdbook-admonish mdbook-toc wasm-bindgen-cli + wasm-pack + # Can't install atm with `--locked` + - cargo install mdbook-footnote + - cmd: | + [ "$(which cargo-insta)" ] || echo "🔴 Can't find a binary that cargo just installed. Is the cargo bin path (generally at ~/.cargo/bin) on the \$PATH?" + silent: true diff --git a/Taskfile.yml b/Taskfile.yml index 727f2a3220fb..6ea88606fff2 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -11,6 +11,9 @@ version: "3" +includes: + cargo-tools: ./Taskfile.cargo-tools.yml + vars: # Keep in sync with .vscode/extensions.json vscode_extensions: | @@ -38,7 +41,7 @@ tasks: desc: Install tools for PRQL development. cmds: - - task: install-cargo-tools + - task: cargo-tools:install - task: install-brew-dependencies - task: install-maturin - task: install-pre-commit @@ -52,31 +55,11 @@ tasks: 🟢 Setup complete! ✅🚀" silent: true - setup-devcontainer: - desc: Install tools for PRQL development (Rust, JS, Python). - cmds: - - task: install-maturin - - task: install-npm-dependencies - - task: install-cargo-tools - - cmd: | - echo " - 🟢 Setup complete! ✅🚀" - silent: true - install-cargo-tools: # factored this out because it takes a long time to build - desc: Install cargo tools for PRQL development. - cmds: - # `--locked` installs from the underlying lock files (which is not the - # default?!) - - cargo install --locked bacon cargo-audit cargo-insta cargo-release - default-target mdbook mdbook-admonish mdbook-toc wasm-bindgen-cli - wasm-pack - # Can't install atm with `--locked` - - cargo install mdbook-footnote - - cmd: | - [ "$(which cargo-insta)" ] || echo "🔴 Can't find a binary that cargo just installed. Is the cargo bin path (generally at ~/.cargo/bin) on the \$PATH?" - silent: true + desc: Alias of `cargo-tools:install` + deps: + - cargo-tools:install install-maturin: desc: Install maturin.