Skip to content

Commit

Permalink
Build docker image in GH action and publish to ghcr
Browse files Browse the repository at this point in the history
  • Loading branch information
milot-mirdita committed Jul 12, 2022
1 parent 678c82a commit eb203d3
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 55 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"
release:
types: [published]
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 }}
99 changes: 44 additions & 55 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,65 +1,54 @@
ARG NAMESPACE=
FROM debian:stable-slim as qemu-downloader
ARG NAMESPACE
RUN if [ X"$NAMESPACE" != X"" ]; then \
apt-get update && apt-get install -y wget && rm -rf /var/lib/apt/lists/*; \
fi; \
if [ X"$NAMESPACE" = X"ppc64le/" ]; then \
wget -nv -O /usr/bin/qemu-ppc64le-static https://github.com/multiarch/qemu-user-static/releases/download/v4.2.0-4/qemu-ppc64le-static; \
chmod +x /usr/bin/qemu-ppc64le-static; \
fi; \
if [ X"$NAMESPACE" = X"aarch64/" ]; then \
wget -nv -O /usr/bin/qemu-aarch64-static https://github.com/multiarch/qemu-user-static/releases/download/v4.2.0-4/qemu-aarch64-static; \
chmod +x /usr/bin/qemu-aarch64-static; \
fi; \
touch /usr/bin/dummy_copy

FROM ${NAMESPACE}debian:stable-slim as builder
ARG NAMESPACE
COPY --from=qemu-downloader /usr/bin/dummy_copy /usr/bin/qemu-aarch64-static* /usr/bin/qemu-ppc64le-static* /usr/bin/

RUN apt-get update && apt-get install -y \
build-essential cmake xxd git zlib1g-dev libbz2-dev libatomic1 \
&& rm -rf /var/lib/apt/lists/*
ARG APP=mmseqs
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/mmseqs
WORKDIR /opt/build
ADD . .

RUN mkdir -p build_sse2/src && mkdir -p build_sse41/src && mkdir -p build_avx/src && mkdir -p build/src; \
if [ X"$NAMESPACE" = X"" ]; then \
cd /opt/mmseqs/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/mmseqs /opt/mmseqs/mmseqs_sse2; \
cd /opt/mmseqs/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/mmseqs /opt/mmseqs/mmseqs_sse41; \
cd /opt/mmseqs/build_avx; \
cmake -DHAVE_AVX2=1 -DHAVE_MPI=0 -DHAVE_TESTS=0 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=. ..; \
make -j $(nproc --all); \
mv src/mmseqs /opt/mmseqs/mmseqs_avx2; \
touch /opt/mmseqs/mmseqs_arch; \
else \
cd /opt/mmseqs/build; \
cmake -DHAVE_MPI=0 -DHAVE_TESTS=0 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=. ..; \
make -j $(nproc --all); \
mv src/mmseqs /opt/mmseqs/mmseqs_arch; \
touch /opt/mmseqs/mmseqs_sse2 /opt/mmseqs/mmseqs_sse42 /opt/mmseqs/mmseqs_avx2; \
fi

FROM ${NAMESPACE}debian:stable-slim
ARG NAMESPACE
MAINTAINER Milot Mirdita <[email protected]>
COPY --from=qemu-downloader /usr/bin/dummy_copy /usr/bin/qemu-aarch64-static* /usr/bin/qemu-ppc64le-static* /usr/bin/
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
ARG TARGETARCH
ARG APP

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=builder /opt/mmseqs/mmseqs_arch /opt/mmseqs/mmseqs_sse2 /opt/mmseqs/mmseqs_sse41 /opt/mmseqs/mmseqs_avx2 /usr/local/bin/
ADD util/mmseqs_wrapper.sh /usr/local/bin/mmseqs
RUN if [ X"$NAMESPACE" != X"" ]; then mv -f /usr/local/bin/mmseqs_arch /usr/local/bin/mmseqs; fi
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/entrypoint
RUN if [ "$TARGETARCH" = "arm64" ]; then rm -f /usr/local/bin/entrypoint; ln -s /usr/local/bin/${APP}_arch /usr/local/bin/entrypoint; fi

CMD ["/usr/local/bin/mmseqs"]
ENTRYPOINT ["/usr/local/bin/entrypoint"]

0 comments on commit eb203d3

Please sign in to comment.