Skip to content

Commit 226e758

Browse files
committed
Merge branch 'belt/main'
2 parents bb30e52 + 4ca7f6c commit 226e758

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

README.md

+29
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,35 @@ What follows is a list of known failures.
226226

227227
- On Fedora, `perl` needs to be installed for `OpenSSL` to build properly. This can be done with the following command:
228228
`dnf install perl` (see [this issue](https://github.com/Byron/gitoxide/issues/592)).
229+
-
230+
### Using Docker
231+
232+
Some CI/CD pipelines leverage repository cloning. Below is a copy-paste-able example to build docker images for such workflows.
233+
As no official image exists (at this time), an image must first be built.
234+
235+
#### Building the most compatible base image
236+
237+
```sh
238+
docker build -f etc/docker/Dockerfile.alpine -t gitoxide:latest --compress . --target=pipeline
239+
```
240+
241+
#### Basic usage in a Pipeline
242+
243+
For example, if a `Dockerfile` currently uses something like `RUN git clone https://github.com/Byron/gitoxide`, first build the image:
244+
245+
```sh
246+
docker build -f etc/docker/Dockerfile.alpine -t gitoxide:latest --compress .
247+
```
248+
249+
Then copy the binaries into your image and replace the `git` directive with a `gix` equivalent.
250+
251+
```dockerfile
252+
COPY --from gitoxide:latest /bin/gix /usr/local/bin/
253+
COPY --from gitoxide:latest /bin/ein /usr/local/bin/
254+
255+
RUN /usr/local/bin/gix clone --depth 1 https://github.com/Byron/gitoxide gitoxide
256+
```
257+
229258

230259
[releases]: https://github.com/Byron/gitoxide/releases
231260
[rustup]: https://rustup.rs

etc/docker/Dockerfile.alpine

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Please note that this file is not regularly tested, and you are welcome to create PRs with fixes as needed.
2+
ARG GITOXIDE_VERSION=0.36.0
3+
4+
FROM rust:alpine AS bootstrap_os
5+
# hadolint ignore=DL3018
6+
RUN apk upgrade --update-cache --available \
7+
&& apk add --no-cache --virtual .runtime-gitoxide libressl zlib-ng \
8+
libressl3.8-libcrypto
9+
10+
11+
FROM bootstrap_os AS bootstrap_build_deps
12+
# hadolint ignore=DL3018
13+
RUN apk add --no-cache --virtual .rust-builder cmake gcc musl-dev make pkgconfig \
14+
&& apk add --no-cache --virtual .bootstrap-gitoxide libressl-dev zlib-ng \
15+
libressl3.8-libcrypto
16+
17+
18+
FROM bootstrap_build_deps AS bootstrap_builder
19+
ARG GITOXIDE_VERSION
20+
21+
ENV RUST_BACKTRACE=1
22+
23+
RUN cargo install gitoxide --version "${GITOXIDE_VERSION}" --message-format short \
24+
&& apk del .bootstrap-gitoxide \
25+
&& apk del .rust-builder
26+
27+
28+
FROM alpine:3.13.3 AS pipeline
29+
# hadolint ignore=SC2016
30+
RUN apk upgrade --update-cache --available \
31+
&& { \
32+
echo '#!/bin/sh'; \
33+
echo 'set -eu'; \
34+
echo 'if [ "${#}" -gt 0 ] && [ "${1#-}" = "${1}" ] \'; \
35+
echo ' && command -v "${1}" > "/dev/null" 2>&1; then'; \
36+
echo ' exec "${@}"'; \
37+
echo 'else exec /bin/shfmt "${@}"; fi'; \
38+
echo 'exit 0'; \
39+
} > /init && chmod +x /init
40+
41+
COPY --from=bootstrap_builder /usr/local/cargo/bin/gix /usr/local/cargo/bin/
42+
COPY --from=bootstrap_builder /usr/local/cargo/bin/ein /usr/local/cargo/bin/
43+
44+
WORKDIR /usr/local/cargo/bin
45+
46+
SHELL [ "/bin/ash", "-o", "pipefail", "-c" ]
47+
48+
RUN find . -type f -executable -not \( -name '*tkinter*' \) -exec ldd '{}' ';' \
49+
| awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); gsub(".*/", "", so); print so }' \
50+
| xargs -r apk search -f | awk '{ so = $(NF-1); gsub(/-\d+.*$/, "", so); print so }' \
51+
| xargs -r apk add --no-cache --virtual .runtime
52+
53+
ENV PATH="/usr/local/cargo/bin:${PATH}"
54+
55+
WORKDIR /root
56+
57+
HEALTHCHECK --retries=1 --timeout=15s CMD gix help
58+
59+
ENTRYPOINT [ "/init" ]
60+
61+
62+
FROM scratch
63+
COPY --from=bootstrap_builder /usr/local/cargo/bin/gix /bin/
64+
COPY --from=bootstrap_builder /usr/local/cargo/bin/ein /bin/
65+
66+
ENTRYPOINT [ "/bin/gix" ]
67+
68+
CMD [ "/bin/gix" ]
69+
70+
# vi: nospell

0 commit comments

Comments
 (0)