Skip to content

Commit 102233f

Browse files
committed
Fix docker ci
1 parent 74083a0 commit 102233f

3 files changed

Lines changed: 49 additions & 50 deletions

File tree

.github/workflows/publish_docker.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@ name: docker
22

33
on:
44
push:
5-
branches:
6-
- 'master'
75
tags:
86
- 'v*'
9-
pull_request:
10-
branches:
11-
- 'master'
127

138
jobs:
149
docker:
15-
runs-on: ubuntu-latest
10+
runs-on: ubuntu-20.04
1611
steps:
1712
- name: Checkout
1813
uses: actions/checkout@v2

Dockerfile

Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,27 @@
1-
FROM phusion/baseimage:0.11 as builder
2-
LABEL maintainer "xuliuchengxlc@gmail.com"
3-
LABEL description="The build stage for ChainX. We create the ChainX binary in this stage."
4-
5-
ARG PROFILE=release
6-
ARG APP=chainx
7-
ARG RUSTC_VERSION=nightly-2021-11-07
8-
9-
WORKDIR /$APP
10-
11-
COPY . /$APP
12-
13-
RUN apt-get update && \
14-
apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" dist-upgrade -y && \
15-
apt-get install -y cmake pkg-config libssl-dev git clang
16-
17-
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \
18-
export PATH=$PATH:$HOME/.cargo/bin && \
19-
rustup toolchain install $RUSTC_VERSION && \
20-
rustup target add wasm32-unknown-unknown --toolchain $RUSTC_VERSION && \
21-
cargo +$RUSTC_VERSION build --$PROFILE
22-
23-
# ===== SECOND STAGE ======
24-
25-
FROM phusion/baseimage:0.11
26-
LABEL maintainer "xuliuchengxlc@gmail.com"
27-
LABEL description="A very small image where we copy the ChainX binary created from the builder image."
28-
29-
ARG PROFILE=release
30-
ARG APP=chainx
31-
32-
COPY --from=builder /$APP/target/$PROFILE/$APP /usr/local/bin
33-
34-
RUN mv /usr/share/ca* /tmp && \
35-
rm -rf /usr/share/* && \
36-
mv /tmp/ca-certificates /usr/share/ && \
37-
rm -rf /usr/lib/python* && \
38-
mkdir -p /root/.local/share/chainx && \
39-
ln -s /root/.local/share/chainx /data
40-
41-
RUN rm -rf /usr/bin /usr/sbin
42-
43-
EXPOSE 20222 8086 8087 9615
44-
1+
# This is the build stage for ChainX. Here we create the binary.
2+
FROM docker.io/paritytech/ci-linux:production as builder
3+
4+
WORKDIR /chainx
5+
COPY . /chainx
6+
RUN cargo build --locked --release
7+
8+
# This is the 2nd stage: a very small image where we copy the ChainX binary."
9+
FROM docker.io/library/ubuntu:20.04
10+
11+
COPY --from=builder /chainx/target/release/chainx /usr/local/bin
12+
13+
RUN useradd -m -u 1000 -U -s /bin/sh -d /chainx chainx && \
14+
mkdir -p /data /chainx/.local/share/chainx && \
15+
chown -R chainx:chainx /data && \
16+
ln -s /data /chainx/.local/share/chainx && \
17+
# unclutter and minimize the attack surface
18+
rm -rf /usr/bin /usr/sbin && \
19+
# Sanity checks
20+
ldd /usr/local/bin/chainx && \
21+
/usr/local/bin/chainx --version
22+
23+
USER chainx
24+
EXPOSE 30333 9933 9944 9615
4525
VOLUME ["/data"]
4626

4727
CMD ["/usr/local/bin/chainx"]

scripts/build-docker.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
pushd .
5+
6+
# The following line ensure we run from the project root
7+
PROJECT_ROOT=`git rev-parse --show-toplevel`
8+
cd $PROJECT_ROOT
9+
10+
# Find the current version from Cargo.toml
11+
VERSION=`grep "^version" ./cli/Cargo.toml | egrep -o "([0-9\.]+)"`
12+
GITUSER=chainxorg
13+
GITREPO=chainx
14+
15+
# Build the image
16+
echo "Building ${GITUSER}/${GITREPO}:latest docker image, hang on!"
17+
time docker build -f ./Dockerfile -t ${GITUSER}/${GITREPO}:latest .
18+
docker tag ${GITUSER}/${GITREPO}:latest ${GITUSER}/${GITREPO}:v${VERSION}
19+
20+
# Show the list of available images for this repo
21+
echo "Image is ready"
22+
docker images | grep ${GITREPO}
23+
24+
popd

0 commit comments

Comments
 (0)