Skip to content

Instantly share code, notes, and snippets.

@popunbom
Last active June 29, 2024 14:42
Show Gist options
  • Select an option

  • Save popunbom/b5b6018058e3f35e930d271859e2775c to your computer and use it in GitHub Desktop.

Select an option

Save popunbom/b5b6018058e3f35e930d271859e2775c to your computer and use it in GitHub Desktop.
YAFU (Yet Another Factoring Utility) on Docker
###########
# Stage-1 #
###########
FROM alpine:3 AS builder
# Add 'testing' repository
RUN echo '@testing http://dl-cdn.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories
# Install build dependencies
RUN apk add \
git curl make gcc musl-dev gmp-dev zlib-dev \
ecm-dev@testing
WORKDIR /src
# Build: msieve
RUN curl -L https://sourceforge.net/projects/msieve/files/msieve/Msieve%20v1.53/msieve153_src.tar.gz/download \
| tar xzvf - \
&& mv msieve* msieve \
&& make -C msieve all -j8 ECM=1 NO_ZLIB=1
# Build: ytools
RUN git clone --depth=1 --recursive https://github.com/bbuhrow/ytools \
&& make -C ytools -j8 CC=gcc
# Build: ysieve
RUN git clone --depth=1 --recursive https://github.com/bbuhrow/ysieve \
&& make -C ysieve -j8
# Build: yafu
RUN git clone --depth=1 --recursive https://github.com/bbuhrow/yafu \
&& make -C yafu NFS=1 -j8
###########
# Stage-2 #
###########
FROM alpine:3
# Add 'testing' repository
RUN echo '@testing http://dl-cdn.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories
# Install executable dependencies
RUN apk add \
musl gmp ecm@testing
# Copy from Stage-1
WORKDIR /yafu
COPY --from=builder /src/yafu/yafu .
COPY --from=builder /src/yafu/yafu.ini .
ENTRYPOINT [ "/yafu/yafu" ]
@popunbom
Copy link
Author

Usage

$ curl -fsSL https://gist.githubusercontent.com/popunbom/b5b6018058e3f35e930d271859e2775c/raw/Dockerfile | docker build -t yafu:latest -f - .
[+] Building 45.7s (16/16) FINISHED                                                                                                                                                                                    docker:rancher-desktop
 => [internal] load build definition from Dockerfile                                                                                                                                                                                     0.0s
 => => transferring dockerfile: 1.02kB                                                                                                                                                                                                   0.0s
 => [internal] load metadata for docker.io/library/alpine:3                                                                                                                                                                              2.1s
 => [internal] load .dockerignore                                                                                                                                                                                                        0.0s
 => => transferring context: 2B                                                                                                                                                                                                          0.0s
 => [stage-1 1/6] FROM docker.io/library/alpine:3@sha256:b89d9c93e9ed3597455c90a0b88a8bbb5cb7188438f70953fede212a0c4394e0                                                                                                                0.5s
 => => resolve docker.io/library/alpine:3@sha256:b89d9c93e9ed3597455c90a0b88a8bbb5cb7188438f70953fede212a0c4394e0                                                                                                                        0.0s
 => => sha256:b89d9c93e9ed3597455c90a0b88a8bbb5cb7188438f70953fede212a0c4394e0 1.85kB / 1.85kB                                                                                                                                           0.0s
 => => sha256:dabf91b69c191a1a0a1628fd6bdd029c0c4018041c7f052870bb13c5a222ae76 528B / 528B                                                                                                                                               0.0s
 => => sha256:a606584aa9aa875552092ec9e1d62cb98d486f51f389609914039aabd9414687 1.47kB / 1.47kB                                                                                                                                           0.0s
 => => sha256:ec99f8b99825a742d50fb3ce173d291378a46ab54b8ef7dd75e5654e2a296e99 3.62MB / 3.62MB                                                                                                                                           0.3s
 => => extracting sha256:ec99f8b99825a742d50fb3ce173d291378a46ab54b8ef7dd75e5654e2a296e99                                                                                                                                                0.2s
 => [stage-1 2/6] RUN echo '@testing http://dl-cdn.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories                                                                                                                         0.3s
 => [builder 3/8] RUN apk add   git curl make gcc musl-dev gmp-dev zlib-dev   ecm-dev@testing                                                                                                                                            4.1s
 => [stage-1 3/6] RUN apk add   musl gmp ecm@testing                                                                                                                                                                                     2.1s
 => [stage-1 4/6] WORKDIR /yafu                                                                                                                                                                                                          0.1s
 => [builder 4/8] WORKDIR /src                                                                                                                                                                                                           0.0s
 => [builder 5/8] RUN curl -L https://sourceforge.net/projects/msieve/files/msieve/Msieve%20v1.53/msieve153_src.tar.gz/download   | tar xzvf -   && mv msieve* msieve   && make -C msieve all -j8 ECM=1 NO_ZLIB=1                       12.8s
 => [builder 6/8] RUN git clone --depth=1 --recursive https://github.com/bbuhrow/ytools   && make -C ytools -j8 CC=gcc                                                                                                                   1.8s
 => [builder 7/8] RUN git clone --depth=1 --recursive https://github.com/bbuhrow/ysieve   && make -C ysieve -j8                                                                                                                          5.3s
 => [builder 8/8] RUN git clone --depth=1 --recursive https://github.com/bbuhrow/yafu   && make -C yafu NFS=1 -j8                                                                                                                       18.7s
 => [stage-1 5/6] COPY --from=builder /src/yafu/yafu .                                                                                                                                                                                   0.0s
 => [stage-1 6/6] COPY --from=builder /src/yafu/yafu.ini .                                                                                                                                                                               0.0s
 => exporting to image                                                                                                                                                                                                                   0.0s
 => => exporting layers                                                                                                                                                                                                                  0.0s
 => => writing image sha256:69a96b707a14ba9db84a6c81d71df837844f051d15e2e28de138180508de53f9                                                                                                                                             0.0s
 => => naming to docker.io/library/yafu:latest

$ docker run --rm -it yafu:latest "factor(12345)"


fac: factoring 12345
fac: using pretesting plan: normal
fac: no tune info: using qs/gnfs crossover of 100 digits
fac: no tune info: using qs/snfs crossover of 75 digits
div: primes less than 10000
Total factoring time = 0.0002 seconds


***factors found***

P1 = 3
P1 = 5
P3 = 823

ans = 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment