From 8deba835b7529fc5b16c0a5846f0dbd611eb6cbc Mon Sep 17 00:00:00 2001 From: rzadp Date: Wed, 29 May 2024 13:18:19 +0200 Subject: [PATCH] Try to build docker on ci --- .dockerignore | 1 + .github/workflows/build-docker.yml | 30 ++++++++++++++++++++++++++++++ Dockerfile | 30 ++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/build-docker.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b60de5b --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +**/target diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml new file mode 100644 index 0000000..ca7d3b6 --- /dev/null +++ b/.github/workflows/build-docker.yml @@ -0,0 +1,30 @@ +name: Build docker image + +on: + push: + branches: + - main + - master + - rzadp/test-dockerfile + + +jobs: + ci: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + # We've run into out-of-disk error when compiling Polkadot in the next step, so we free up some space this way. + - name: Free Disk Space (Ubuntu) + uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # 1.3.1 + with: + android: true # This alone is a 12 GB save. + # We disable the rest because it caused some problems. (they're enabled by default) + # The Android removal is enough. + dotnet: false + haskell: false + large-packages: false + swap-storage: false + + - name: Build the docker image + run: docker build . -t polkadot-sdk-minimal-template diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..17216ab --- /dev/null +++ b/Dockerfile @@ -0,0 +1,30 @@ +# This is the build stage for Polkadot. Here we create the binary in a temporary image. +FROM docker.io/paritytech/ci-linux:production as builder + +WORKDIR /polkadot +COPY . /polkadot + +RUN cargo build --locked --release + +# This is the 2nd stage: a very small image where we copy the Polkadot binary." +FROM docker.io/parity/base-bin:latest + +LABEL description="Multistage Docker image for Polkadot: a platform for web3" + +COPY --from=builder /polkadot/target/release/polkadot /usr/local/bin + +RUN useradd -m -u 1000 -U -s /bin/sh -d /polkadot polkadot && \ + mkdir -p /data /polkadot/.local/share && \ + chown -R polkadot:polkadot /data && \ + ln -s /data /polkadot/.local/share/polkadot && \ +# unclutter and minimize the attack surface + rm -rf /usr/bin /usr/sbin && \ +# check if executable works in this container + /usr/local/bin/polkadot --version + +USER polkadot + +EXPOSE 30333 9933 9944 9615 +VOLUME ["/data"] + +ENTRYPOINT ["/usr/local/bin/polkadot"]