From 1d61be193aa2571a7a8c42db2bc212b0a2f9196f Mon Sep 17 00:00:00 2001 From: Bryan Chen Date: Wed, 8 Feb 2023 15:50:28 +1300 Subject: [PATCH] docker flow --- .github/workflows/docker.yml | 43 ++++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 2 +- Dockerfile | 31 ++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/docker.yml create mode 100644 Dockerfile diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..c61a73d --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,43 @@ +name: docker + +on: + workflow_dispatch: + inputs: + branch: + description: Branch to build docker image (optional). + required: false + type: string + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + ref: ${{ github.event.inputs.branch || github.ref }} + submodules: recursive + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: acala/${{ github.event.repository.name }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=ref,event=tag + type=sha + type=sha,format=long + type=raw,value=latest,enable={{is_default_branch}} + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 575b45e..e59b42d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: steps: - uses: actions/checkout@v3 with: - submodules: recursive + submodules: recursive - name: Check format run: cargo fmt --all -- --check - name: Check clippy diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cee0db8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM rust:buster as builder +WORKDIR /app + +COPY . . + +RUN cargo build --release --verbose + +# ============= + +FROM phusion/baseimage:focal-1.2.0 +LABEL maintainer="hello@acala.network" + +RUN useradd -m -u 1000 -U -s /bin/sh -d /app docker + +WORKDIR /app + +COPY --from=builder /app/target/release/subway /usr/local/bin +COPY ./config.yml /app/config.yml + +# checks +RUN ldd /usr/local/bin/subway && \ + /usr/local/bin/subway --version + +# Shrinking +RUN rm -rf /usr/lib/python* && \ + rm -rf /usr/sbin /usr/share/man + +USER docker +EXPOSE 9944 + +ENTRYPOINT ["/usr/local/bin/subway"]