Skip to content

Commit 125fac8

Browse files
Dockerfile improvements
- make -z defs work with bpf sources calling sol_invoke - add build-bpf.sh, intended to be shared by serum-pyth - remove GITHUB_WORKSPACE reference from dockerfile - old behavior was expanding to an empty string - instead ensure build context is workspace in docker.yaml - make SOLANA_VERSION available for docker run/inspect - workflow step names, comments, whitespace
1 parent 981969b commit 125fac8

File tree

3 files changed

+117
-27
lines changed

3 files changed

+117
-27
lines changed

.github/workflows/docker.yaml

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,53 @@ on:
77

88
env:
99
SOLANA_VERSION: 1.7.12
10+
DOCKER_SERVER: docker.io
1011

1112
jobs:
1213
build:
1314
runs-on: ubuntu-latest
1415

1516
steps:
1617
- uses: actions/checkout@v2
17-
- run: echo "BRANCH=$( echo ${GITHUB_REF##*/} )" >> $GITHUB_ENV
18-
- run: echo "DOCKER_TAG=${BRANCH}" >> $GITHUB_ENV
19-
- run: echo "DOCKER_IMAGE=$( echo ${GITHUB_REPOSITORY}:${DOCKER_TAG} )" >> $GITHUB_ENV
20-
- run: docker build -f docker/Dockerfile --build-arg SOLANA_VERSION=${{ env.SOLANA_VERSION }} --tag ${{ env.DOCKER_IMAGE }} .
21-
# publish to docker.io
22-
- run: echo "${{ secrets.DOCKER_IO_PASS }}" | docker login docker.io -u ${{ secrets.DOCKER_IO_USER }} --password-stdin
23-
if: startsWith( github.ref, 'refs/tags/' )
24-
- run: docker image tag ${DOCKER_IMAGE} docker.io/pythfoundation/pyth-client:${DOCKER_TAG}
25-
if: startsWith( github.ref, 'refs/tags/' )
26-
- run: docker image push docker.io/pythfoundation/pyth-client:${DOCKER_TAG}
27-
if: startsWith( github.ref, 'refs/tags/' )
18+
19+
- name: Initialize Environment
20+
run: |
21+
set -eux
22+
DOCKER_IMAGE="${GITHUB_REPOSITORY}:${GITHUB_REF##*/}"
23+
echo "DOCKER_IMAGE=${DOCKER_IMAGE}" >> "${GITHUB_ENV}"
24+
25+
- name: Build Docker Image
26+
run: |
27+
set -eux
28+
29+
# GITHUB_WORKSPACE may be relative to "/".
30+
cd /
31+
cd "${GITHUB_WORKSPACE}"
32+
33+
docker build \
34+
--file docker/Dockerfile \
35+
--build-arg SOLANA_VERSION="${{ env.SOLANA_VERSION }}" \
36+
--tag "${{ env.DOCKER_IMAGE }}" \
37+
.
38+
39+
- name: Publish Docker Image
40+
run: |
41+
# Do not set -x before referencing secrets.
42+
set -eu
43+
44+
echo "${{ secrets.DOCKER_IO_PASS }}" | docker login \
45+
"${{ env.DOCKER_SERVER }}" \
46+
-u "${{ secrets.DOCKER_IO_USER }}" \
47+
--password-stdin
48+
49+
set -x
50+
SRC="${{ env.DOCKER_IMAGE }}"
51+
DST="${{ env.DOCKER_SERVER }}/${SRC}"
52+
docker image tag "${SRC}" "${DST}"
53+
docker image push "${DST}"
54+
55+
# Only publish if tagged as a release.
56+
if: |
57+
startsWith( github.ref, 'refs/tags/devnet-' )
58+
|| startsWith( github.ref, 'refs/tags/testnet-' )
59+
|| startsWith( github.ref, 'refs/tags/mainnet-' )

docker/Dockerfile

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,67 @@
11
ARG SOLANA_VERSION
2-
32
FROM solanalabs/solana:v${SOLANA_VERSION}
43

4+
# Redeclare SOLANA_VERSION in the new build stage.
5+
# Persist in env for docker run & inspect.
6+
ARG SOLANA_VERSION
7+
ENV SOLANA_VERSION="${SOLANA_VERSION}"
8+
59
RUN apt-get update
6-
RUN apt-get install -qq cmake curl g++ gcc-multilib git libzstd1 libzstd-dev python3-pytest sudo zlib1g zlib1g-dev
10+
RUN apt-get install -qq \
11+
cmake \
12+
curl \
13+
g++ \
14+
gcc-multilib \
15+
git \
16+
libzstd1 \
17+
libzstd-dev \
18+
python3-pytest \
19+
sudo \
20+
zlib1g \
21+
zlib1g-dev
722

823
# Grant sudo access to pyth user
924
RUN echo "pyth ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
10-
1125
RUN useradd -m pyth
26+
1227
USER pyth
1328
WORKDIR /home/pyth
29+
COPY --chown=pyth:pyth . pyth-client/
1430

15-
COPY --chown=pyth:pyth ${GITHUB_WORKSPACE} pyth-client/
31+
RUN echo "\n\
32+
export PATH=\"\${PATH}:\${HOME}/pyth-client/build\"\n\
33+
export PYTHONPATH=\"\${PYTHONPATH:+\$PYTHONPATH:}\${HOME}/pyth-client\"\n\
34+
" >> .profile
1635

36+
# Build off-chain binaries.
1737
RUN cd pyth-client && ./scripts/build.sh
1838

19-
RUN echo "\nexport PATH=\$PATH:\$HOME/pyth-client/build" >> .profile
20-
21-
RUN echo "\nexport PYTHONPATH=\${PYTHONPATH:+\${PYTHONPATH}:}\$HOME/pyth-client" >> .profile
39+
# Install rust and add ". ~/.cargo/env" to ~/.profile.
40+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
41+
| sh -s -- -y --default-toolchain none
2242

23-
# Install Rust
24-
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none
43+
# Copy solana sdk to modify makefile and header.
44+
RUN mkdir solana
45+
RUN cp -a /usr/bin/sdk solana
2546

26-
# Link Solana location for makefile
27-
RUN mkdir solana && cp -a /usr/bin/sdk solana && sed -i 's/-Werror/-Wall -Wextra -Wconversion -Werror/g' solana/sdk/bpf/c/bpf.mk && sed -i 's/-z notext/-z notext -z defs/g' solana/sdk/bpf/c/bpf.mk
47+
# Enable all clang warnings.
48+
RUN sed -i \
49+
's/-Werror/-Wall -Wextra -Wconversion -Werror/g' \
50+
solana/sdk/bpf/c/bpf.mk
2851

29-
# Build the program
30-
RUN PATH=$PATH:$HOME/.cargo/bin && cd pyth-client/program && make V=1
52+
# Disallow missing symbols in ld.
53+
RUN sed -i \
54+
's/-z notext/-z notext -z defs/g' \
55+
solana/sdk/bpf/c/bpf.mk
3156

32-
# Print hash of the program
33-
RUN sha256sum -b pyth-client/target/oracle.so
57+
# https://github.com/solana-labs/solana/issues/21198
58+
RUN sed -i \
59+
's/\(^uint64_t sol_invoke_signed_c(\)/__attribute__(( weak )) \1/g' \
60+
solana/sdk/bpf/c/inc/solana_sdk.h
3461

62+
# Build and test the oracle program.
63+
RUN cd pyth-client && ./scripts/build-bpf.sh program
3564
RUN /bin/bash -l -c "pytest-3 --pyargs pyth"
3665

3766
ENTRYPOINT []
3867
CMD []
39-

scripts/build-bpf.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Build given bpf makefile dir (./program by default):
4+
# ~/pyth-client$ ./scripts/build-bpf.sh
5+
# ~/pyth-client/program$ ../scripts/build-bpf.sh .
6+
# ~/$ ./pyth-client/scripts/build-bpf.sh ./serum-pyth/program
7+
#
8+
9+
set -eu
10+
11+
BUILD_DIR="$( cd "${1:-program}" && pwd )"
12+
13+
if [[ ! -f "${BUILD_DIR}/makefile" ]]
14+
then
15+
>&2 echo "Not a makefile dir: ${BUILD_DIR}"
16+
exit 1
17+
fi
18+
19+
if ! which cargo 2> /dev/null
20+
then
21+
# shellcheck disable=SC1090
22+
source "${CARGO_HOME:-$HOME/.cargo}/env"
23+
fi
24+
25+
set -x
26+
27+
cd "${BUILD_DIR}"
28+
make V=1 clean
29+
make V=1 "${@:2}"
30+
sha256sum ../target/*.so

0 commit comments

Comments
 (0)