Skip to content

Commit b821159

Browse files
Artifact builds upon release (#302)
These changes will allow Github Actions to build Debian packages to be created and attached to releases whenever releases are made.
1 parent f8a9718 commit b821159

File tree

14 files changed

+648
-56
lines changed

14 files changed

+648
-56
lines changed

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ cmake*/
1010
.direnv
1111
plrust/postgrestd
1212
.git
13-
Dockerfile.try
13+
Dockerfile.*
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
# NOTE: This Dockerfile will require a more recent version of Docker that has heredoc support.
2+
#
3+
# Example of how to build this Dockerfile (requires being launched from the root of checkout):
4+
# docker build --build-arg PG_VER=15 --build-arg PLRUST_VER=1.0.2 -f .github/docker/Dockerfile.debian-artifact-build -t plrust-debian .
5+
#
6+
# Example of how to run an image after it has been built (assuming previous step has been done):
7+
# docker run -it --rm plrust-debian /bin/bash
8+
#
9+
# Any artifacts produced will be in the /out directory of the running Docker container. With a container running, an example
10+
# of how to copy out artifacts:
11+
# docker cp container_name:/out .
12+
# which will copy the container's /out directory to the current directory of the host
13+
14+
FROM debian:bullseye
15+
16+
# Args to pass in at build-time. Note that these are defaulted.
17+
ARG PG_VER=15
18+
ARG PLRUST_VER=0.0.0
19+
20+
# Change this value if the entire build cache needs to be busted for any reason.
21+
# Any random value can work here. UUIDs seemed to be a good choice.
22+
ARG CACHE_KEY=2d912233-4423-48f9-b7ba-afc6b2ef3a44
23+
24+
SHELL ["/bin/bash", "-c"]
25+
26+
# Install system-level dependencies. Prefer to install Postgres from the official
27+
# Postgres Debian packages
28+
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections && \
29+
apt-get update && \
30+
apt-get install -y --no-install-recommends \
31+
ca-certificates \
32+
gnupg \
33+
lsb-release \
34+
wget && \
35+
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' && \
36+
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg >/dev/null && \
37+
apt-get update -y -qq --fix-missing && \
38+
apt-get install -y --no-install-recommends \
39+
build-essential \
40+
clang \
41+
clang-11 \
42+
gcc \
43+
git \
44+
jq \
45+
libssl-dev \
46+
llvm-11 \
47+
make \
48+
postgresql-${PG_VER} \
49+
postgresql-server-dev-${PG_VER} \
50+
pkg-config \
51+
ruby && \
52+
rm -rf /var/lib/apt/lists/*
53+
54+
# Install fpm for the creation of the .deb file,
55+
# and install toml so TOML files can be parsed later
56+
RUN gem install --no-document fpm toml
57+
58+
# Set up permissions so that the postgres user can install the plrust plugin
59+
RUN chmod a+rwx `$(which pg_config) --pkglibdir` `$(which pg_config) --sharedir`/extension
60+
61+
# Create the directory for the outgoing .deb package
62+
RUN mkdir /out && chmod 777 /out
63+
64+
# The 'postgres' user is the default user that the official Postgres Debian packages create and set up
65+
USER postgres
66+
ENV USER postgres
67+
68+
# Copy in plrust source
69+
COPY --chown=${USER} . src/
70+
WORKDIR /src
71+
72+
# Obtain the toolchain version from rust-toolchain.toml and store that into a file.
73+
RUN ruby <<EOF
74+
require 'toml'
75+
toml=TOML.load_file('/src/rust-toolchain.toml')
76+
if ver=toml['toolchain']['channel']
77+
File.open('/tmp/.toolchain-ver', 'w') { |file| file.write(ver) }
78+
else
79+
raise 'Could not determine toolchain channel version. Is rust-toolchain.toml missing or malformed?'
80+
end
81+
EOF
82+
83+
# Install Rust
84+
RUN TOOLCHAIN_VER=$(</tmp/.toolchain-ver) && wget -qO- https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain=$TOOLCHAIN_VER
85+
ENV PATH="/var/lib/postgresql/.cargo/bin:${PATH}"
86+
87+
# Install the version of PGRX that is dictated by Cargo.toml for this project
88+
RUN PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[]|select(.name=="pgrx")|.version') && \
89+
cargo install cargo-pgrx --force --version "$PGRX_VERSION"
90+
91+
# Necessary to build plrustc and company
92+
RUN rustup component add llvm-tools-preview rustc-dev
93+
94+
# Build and install plrstuc
95+
RUN cd /src/plrustc && ./build.sh && cp ../build/bin/plrustc ~/.cargo/bin
96+
97+
# Init cargo pgrx
98+
RUN cargo pgrx init --pg${PG_VER} $(which pg_config)
99+
100+
# Build plrust with postgrestd. Architecture is determined by the host running this Dockerfile
101+
# (i.e. no cross-compiling)
102+
RUN cd /src/plrust && STD_TARGETS="$(uname -m)-postgres-linux-gnu" ./build
103+
104+
# Use cargo pgrx package to create everything necessary, placed into RELEASE_DIR below
105+
RUN cd /src/plrust && cargo pgrx package --features trusted
106+
107+
# This is the root of all the files necessary to package up into the .deb file. This specific path is generated by
108+
# 'cargo pgrx package' above
109+
ENV RELEASE_DIR /src/target/release/plrust-pg${PG_VER}
110+
111+
# Create the plrustc location for our distribution, then copy in the plrustc program into the correct spot
112+
RUN mkdir -p ${RELEASE_DIR}$HOME/.cargo/bin && \
113+
cp $HOME/.cargo/bin/plrustc ${RELEASE_DIR}$HOME/.cargo/bin
114+
115+
# The .deb file distribution needs to include the correct postgrestd toolchain files.
116+
RUN cd $HOME/.rustup && \
117+
export TOOLCHAIN_DIR="$(pwd)/$(find * -type d -name '*postgres*' | head -n 1)" && \
118+
mkdir -p "${RELEASE_DIR}$TOOLCHAIN_DIR" && \
119+
cp -r "$TOOLCHAIN_DIR/." "${RELEASE_DIR}$TOOLCHAIN_DIR"
120+
121+
# Creates a PGRX configuration Toml file, as it is required to build plrust user-defined functions
122+
RUN mkdir -p ${RELEASE_DIR}$HOME/.pgrx && \
123+
echo '[configs]' >> ${RELEASE_DIR}$HOME/.pgrx/config.toml && \
124+
echo "pg${PG_VER}='$(command -v pg_config)'" >> ${RELEASE_DIR}$HOME/.pgrx/config.toml
125+
126+
# Create a Debian preinst script that will run before the installation of the pl/Rust package.
127+
# This will check to be sure the proper Rust toolchain and components are set up beforehand.
128+
RUN TOOLCHAIN_VER=$(</tmp/.toolchain-ver) && cat <<EOF > /tmp/preinst
129+
#!/usr/bin/env bash
130+
131+
if ! id -u postgres 2&> /dev/null; then
132+
echo "[!] User 'postgres' does not exist. Have the official Postgres packages been installed yet?"
133+
exit 1
134+
fi
135+
136+
if ! runuser -l postgres -c 'command -v rustup'; then
137+
echo "[!] The 'postgres' user does not have rustup installed. Please see package installation instructions on how to do this.";
138+
exit 1
139+
fi
140+
141+
if ! runuser -l postgres -c 'command -v rustc'; then
142+
echo "[!] The 'postgres' user does not have Rust installed. Please see package installation instructions on how to do this.";
143+
exit 1
144+
fi
145+
146+
if ! runuser -l postgres -c 'rustup toolchain list | grep -q "^$TOOLCHAIN_VER-$(uname -m)\b"'; then
147+
echo "[!] The 'postgres' user does not have the Rust toolchain $TOOLCHAIN_VER-$(uname -m) installed. Please see package installation instructions on how to do this.";
148+
exit 1
149+
fi
150+
151+
if ! runuser -l postgres -c 'rustup component list | grep -q "^rustc-dev-$(uname -m)\b.*(installed)$"'; then
152+
echo "[!] The 'postgres' user does not have the Rust component 'rustc-dev' installed. Please see package installation instructions on how to do this.";
153+
exit 1
154+
fi
155+
156+
if ! runuser -l postgres -c 'rustup toolchain list | grep -q "^$TOOLCHAIN_VER-$(uname -m)\b.*(default)$"'; then
157+
echo "[!] The 'postgres' user does not have the default toolchain set to $TOOLCHAIN_VER. Please see package installation instructions on how to do this.";
158+
exit 1
159+
fi
160+
161+
EOF
162+
163+
# Package everything up based on whatever's in RELEASE_DIR, and send the resulting
164+
# .deb file to the /out directory
165+
RUN TOOLCHAIN_VER=$(</tmp/.toolchain-ver) && \
166+
DEB_FILENAME="plrust-trusted-${PLRUST_VER}_$TOOLCHAIN_VER-debian-pg${PG_VER}-$(dpkg --print-architecture).deb" && \
167+
cd ${RELEASE_DIR} && fpm \
168+
-s dir \
169+
-t deb \
170+
-n plrust \
171+
--deb-pre-depends "postgresql-${PG_VER}" \
172+
-d "postgresql-${PG_VER}" \
173+
-d "postgresql-server-dev-${PG_VER}" \
174+
-m 'Technology Concepts & Design, Inc. <support@tcdi.com>' \
175+
--description 'PL/Rust is a loadable procedural language that enables writing PostgreSQL functions in the Rust programming language.' \
176+
-v ${PLRUST_VER} \
177+
--url 'https://github.com/tcdi/plrust' \
178+
--license 'The PostgreSQL License' \
179+
--category 'Databases' \
180+
--deb-no-default-config-files \
181+
--before-install /tmp/preinst \
182+
-p /out/$DEB_FILENAME \
183+
--deb-user postgres \
184+
--deb-group postgres \
185+
-a native \
186+
.

.github/workflows/docs.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ jobs:
1212
- uses: actions/checkout@v3
1313
with:
1414
fetch-depth: 0
15-
- name: Install mdbook
15+
- name: Install Rust
1616
run: |
17-
mkdir mdbook
18-
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.14/mdbook-v0.4.14-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
19-
echo `pwd`/mdbook >> $GITHUB_PATH
17+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
18+
echo "PATH=$HOME/.cargo/bin:$PATH" >> $GITHUB_ENV
19+
- name: Install mdbook and other preprocessors
20+
run: |
21+
cargo install mdbook mdbook-variables
2022
- name: Deploy GitHub Pages
2123
run: |
2224
# This assumes your book is in the root of your repository.

0 commit comments

Comments
 (0)