Skip to content

Commit

Permalink
Add github action to build docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
milot-mirdita committed Jul 7, 2022
1 parent 31b156a commit 77387d6
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 29 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Create and publish a Docker image

on:
push:
branches:
- "master"
tags:
- 'v*'
workflow_dispatch:

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
76 changes: 47 additions & 29 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,55 @@
FROM debian:stable-slim as foldseek-builder

RUN apt-get update && apt-get upgrade -y && apt-get install -y \
build-essential cmake xxd git zlib1g-dev libbz2-dev \
&& rm -rf /var/lib/apt/lists/*
ARG APP=foldseek
FROM --platform=$BUILDPLATFORM debian:stable-slim as builder
ARG TARGETARCH
ARG APP

RUN dpkg --add-architecture $TARGETARCH \
&& apt-get update \
&& apt-get install -y \
build-essential cmake xxd git \
zlib1g-dev libbz2-dev libatomic1 \
crossbuild-essential-$TARGETARCH zlib1g-dev:$TARGETARCH libbz2-dev:$TARGETARCH \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /opt/foldseek
WORKDIR /opt/build
ADD . .

RUN mkdir -p build_sse/bin && mkdir -p build_avx/bin

WORKDIR /opt/foldseek/build_sse
RUN cmake -DHAVE_SSE4_1=1 -DHAVE_MPI=0 -DHAVE_TESTS=0 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=. ..; \
make -j $(nproc --all) && make install;

WORKDIR /opt/foldseek/build_avx
RUN cmake -DHAVE_AVX2=1 -DHAVE_MPI=0 -DHAVE_TESTS=0 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=. ..; \
make -j $(nproc --all) && make install;
RUN if [ "$TARGETARCH" = "arm64" ]; then \
mkdir -p build_$TARGETARCH/src; \
cd /opt/build/build_$TARGETARCH; \
CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ cmake -DHAVE_ARM8=1 -DHAVE_MPI=0 -DHAVE_TESTS=0 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=. ..; \
make -j $(nproc --all); \
mv src/${APP} /opt/build/${APP}_arch; \
touch /opt/build/${APP}_sse2 /opt/build/${APP}_sse41 /opt/build/${APP}_avx2; \
else \
mkdir -p build_sse2/src && mkdir -p build_sse41/src && mkdir -p build_avx2/src; \
cd /opt/build/build_sse2; \
cmake -DHAVE_SSE2=1 -DHAVE_MPI=0 -DHAVE_TESTS=0 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=. ..; \
make -j $(nproc --all); \
mv src/${APP} /opt/build/${APP}_sse2; \
cd /opt/build/build_sse41; \
cmake -DHAVE_SSE4_1=1 -DHAVE_MPI=0 -DHAVE_TESTS=0 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=. ..; \
make -j $(nproc --all); \
mv src/${APP} /opt/build/${APP}_sse41; \
cd /opt/build/build_avx2; \
cmake -DHAVE_AVX2=1 -DHAVE_MPI=0 -DHAVE_TESTS=0 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=. ..; \
make -j $(nproc --all); \
mv src/${APP} /opt/build/${APP}_avx2; \
touch /opt/build/${APP}_arch; \
fi

FROM debian:stable-slim
MAINTAINER Martin Steinegger <[email protected]>
MAINTAINER Milot Mirdita <[email protected]>
ARG APP

RUN apt-get update && apt-get upgrade -y && apt-get install -y \
gawk bash grep wget libstdc++6 libgomp1 zlib1g libbz2-1.0 \
RUN apt-get update && apt-get install -y \
gawk bash grep libstdc++6 libgomp1 libatomic1 zlib1g libbz2-1.0 wget tar \
&& rm -rf /var/lib/apt/lists/*

COPY --from=foldseek-builder /opt/foldseek/build_sse/bin/foldseek /usr/local/bin/foldseek_sse42
COPY --from=foldseek-builder /opt/foldseek/build_avx/bin/foldseek /usr/local/bin/foldseek_avx2
RUN echo '#!/bin/bash\n\
if $(grep -q -E "^flags.+avx2" /proc/cpuinfo); then\n\
exec /usr/local/bin/foldseek_avx2 "$@"\n\
else\n\
exec /usr/local/bin/foldseek_sse42 "$@"\n\
fi' > /usr/local/bin/foldseek
RUN chmod +x /usr/local/bin/foldseek

ENTRYPOINT ["/usr/local/bin/foldseek"]
COPY --from=builder /opt/build/${APP}_arch /opt/build/${APP}_sse2 /opt/build/${APP}_sse41 /opt/build/${APP}_avx2 /usr/local/bin/
ADD util/${APP}_wrapper.sh /usr/local/bin/${APP}
RUN if [ "$TARGETARCH" = "arm64" ]; then mv -f /opt/build/${APP}_arch /usr/local/bin/${APP}; fi

ENV APP=$APP
ENTRYPOINT /usr/local/bin/${APP}

13 changes: 13 additions & 0 deletions util/foldseek_wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
FLAGS="$(grep -m 1 '^flags' /proc/cpuinfo)"
case "${FLAGS}" in
*avx2*)
exec /usr/local/bin/foldseek_avx2 "$@"
;;
*sse4_1*)
exec /usr/local/bin/foldseek_sse41 "$@"
;;
*)
exec /usr/local/bin/foldseek_sse2 "$@"
;;
esac

0 comments on commit 77387d6

Please sign in to comment.