From 7020b0fce1b9c269d5ce08c645a9883818fd773b Mon Sep 17 00:00:00 2001 From: David Crespo Date: Thu, 16 Jun 2022 23:37:34 -0500 Subject: [PATCH] Bring back docker image (#1211) * Revert "don't build docker images in CI (#1062)" This reverts commit 1e742ff0a27ad553d66e01e2c000553bb2478353. * update readme to mention CLI, not console * the obvious thing would be to use install_prereqs.sh directly, but let's try this instead * give up, attempt to run install_prerequisites.sh * just for fun, remove sudo from install prereqs script * also try copying the install step out of the script, but *before* cargo build * Revert "just for fun, remove sudo from install prereqs script" 5a7503f9fb21fe14805cb6f222dcbf68874a410f * use prereqs script again, this time with workarounds * try and fix the branch name extractor --- .github/workflows/docker-image.yml | 42 ++++++++++++++++++++++++++ Dockerfile | 47 ++++++++++++++++++++++++++++++ README.adoc | 4 +++ 3 files changed, 93 insertions(+) create mode 100644 .github/workflows/docker-image.yml create mode 100644 Dockerfile diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000000..353058a46d --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,42 @@ +# +# GitHub Actions configuration to automatically build and publish a Docker image +# for Omicron. See README for details. +# +name: docker-image +on: push +jobs: + docker-image: + runs-on: ubuntu-18.04 + steps: + # actions/checkout@v2 + - uses: actions/checkout@28c7f3d2b5162b5ddd3dfd9a45aa55eaf396478b + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + - name: Login to GitHub Packages Docker Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract branch name + shell: bash + run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF_NAME//\//-})" + id: extract_branch + - name: Build and push + # This pushes a docker image to github's container registry. + # It is not a public image by default. + # The docs are here: https://github.com/docker/build-push-action + uses: docker/build-push-action@9379083e426e2e84abb80c8c091f5cdeb7d3fd7a + with: + push: ${{ ! startsWith(github.ref, 'refs/heads/dependabot') }} + file: ./Dockerfile + tags: ghcr.io/${{ github.repository_owner }}/omicron:${{ steps.extract_branch.outputs.branch }},ghcr.io/${{ github.repository_owner }}/omicron:${{ github.sha }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..7fde038a9e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,47 @@ +# +# Dockerfile: build a Docker image for Omicron. This is used by the console for +# prototyping and development. This will not be used for deployment to a real +# rack. +# +# ------------------------------------------------------------------------------ +# Cargo Build Stage +# ------------------------------------------------------------------------------ + +FROM rust:latest as cargo-build + +ENV DEBIAN_FRONTEND=noninteractive + +WORKDIR /usr/src/omicron + +COPY . . + +WORKDIR /usr/src/omicron + +# sudo and path thing are only needed to get prereqs script to run +ENV PATH=/usr/src/omicron/out/cockroachdb/bin:/usr/src/omicron/out/clickhouse:${PATH} +RUN apt-get update && apt-get install -y sudo --no-install-recommends && rm -rf /var/lib/apt/lists/* +RUN tools/install_prerequisites.sh -y + +RUN cargo build --release + +# ------------------------------------------------------------------------------ +# Final Stage +# ------------------------------------------------------------------------------ + +FROM debian:sid-slim + +RUN apt-get update && apt-get install -y \ + ca-certificates \ + libpq5 \ + libssl1.1 \ + libsqlite3-0 \ + --no-install-recommends \ + && rm -rf /var/lib/apt/lists/* + + +COPY --from=cargo-build /usr/src/omicron/target/release/nexus /usr/bin/nexus +COPY --from=cargo-build /usr/src/omicron/target/release/omicron-dev /usr/bin/omicron-dev +COPY --from=cargo-build /usr/src/omicron/target/release/omicron-package /usr/bin/omicron-package +COPY --from=cargo-build /usr/src/omicron/target/release/sled-agent-sim /usr/bin/sled-agent-sim + +CMD ["sled-agent-sim"] diff --git a/README.adoc b/README.adoc index 85fa758030..60f27194bd 100644 --- a/README.adoc +++ b/README.adoc @@ -49,6 +49,10 @@ This mode of operation will be used in production. See: xref:docs/how-to-run.adoc[]. +== Docker image + +This repo includes a Dockerfile that builds an image containing the Nexus and sled agent. There's a GitHub Actions workflow that builds and publishes the Docker image. This is used by [cli](https://github.com/oxidecomputer/cli) for testing. This is **not** the way Omicron will be deployed on production systems, but it's a useful vehicle for working with it. + == Configuration reference `nexus` requires a TOML configuration file. There's an example in