Skip to content

Commit

Permalink
use multi stage to build hyperscan
Browse files Browse the repository at this point in the history
  • Loading branch information
flier committed Apr 18, 2023
1 parent 3b0a1d1 commit b790463
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 19 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,24 @@ jobs:
- ubuntu_version: 22.04
hyperscan_version: 5.4.1
pcre_version: 8.45
go_version: 1.20.3
build_flags: -tags hyperscan_v54,chimera
- ubuntu_version: 20.04
hyperscan_version: 5.2.1
pcre_version: 8.45
go_version: 1.19.8
build_flags: -tags hyperscan_v52,chimera
- ubuntu_version: 20.04
hyperscan_version: 5.1.1
pcre_version: 8.45
build_flags: -tags chimera
go_version: 1.18.10
- ubuntu_version: 18.04
hyperscan_version: 4.7.0
pcre_version: 8.42
go_version: 1.18.10
build_flags: -tags hyperscan_v4
name: tests @ ubuntu ${{ matrix.ubuntu_version }} for hyperscan ${{ matrix.hyperscan_version }} w/ ${{ matrix.build_flags }}
env:
LATEST_TAG: flier/gohs:${{ matrix.hyperscan_version }}
steps:
Expand All @@ -52,6 +57,7 @@ jobs:
UBUNTU_VERSION=${{ matrix.ubuntu_version }}
HYPERSCAN_VERSION=${{ matrix.hyperscan_version }}
PCRE_VERSION=${{ matrix.pcre_version }}
GO_VERSION=${{ matrix.go_version }}
tags: ${{ env.LATEST_TAG }}

- name: Test
Expand Down
60 changes: 41 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

ARG UBUNTU_VERSION=22.04

FROM ubuntu:${UBUNTU_VERSION}

ARG GO_VERSION=1.20.3
ARG HYPERSCAN_VERSION=5.4.1
ARG PCRE_VERSION=8.45
FROM ubuntu:${UBUNTU_VERSION} as build

# Install dependencies

Expand All @@ -31,20 +27,10 @@ RUN <<EOT bash
rm -rf /var/lib/apt/lists/*
EOT

# Install golang

ADD https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz /

RUN <<EOT bash
rm -rf /usr/local/go
tar -C /usr/local -xzf /go${GO_VERSION}.linux-amd64.tar.gz
rm /go${GO_VERSION}.linux-amd64.tar.gz
EOT

ENV PATH="/usr/local/go/bin:${PATH}"

# Download Hyperscan

ARG HYPERSCAN_VERSION=5.4.1

ENV HYPERSCAN_DIR=/hyperscan

WORKDIR ${HYPERSCAN_DIR}
Expand All @@ -55,6 +41,8 @@ RUN <<EOT bash
rm /hyperscan-v${HYPERSCAN_VERSION}.tar.gz
EOT

ARG PCRE_VERSION=8.45

ADD https://sourceforge.net/projects/pcre/files/pcre/${PCRE_VERSION}/pcre-${PCRE_VERSION}.tar.gz/download /pcre-${PCRE_VERSION}.tar.gz

WORKDIR ${HYPERSCAN_DIR}/pcre
Expand All @@ -66,7 +54,7 @@ EOT

# Install Hyperscan

ENV INSTALL_DIR=/usr/local
ENV INSTALL_DIR=/dist

WORKDIR ${HYPERSCAN_DIR}/build

Expand All @@ -83,7 +71,41 @@ RUN <<EOT bash
mv ${HYPERSCAN_DIR}/build/lib/lib*.a ${INSTALL_DIR}/lib/
EOT

ENV PKG_CONFIG_PATH="${INSTALL_DIR}/lib/pkgconfig"
FROM ubuntu:${UBUNTU_VERSION}

# Install dependencies

ENV DEBIAN_FRONTEND noninteractive

# hadolint ignore=DL3008
RUN <<EOT bash
apt-get update
apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
libpcap-dev \
pkg-config
rm -rf /var/lib/apt/lists/*
EOT

# Install golang

ARG GO_VERSION=1.20.3

ADD https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz /

RUN <<EOT bash
tar -C /usr/local -xzf /go${GO_VERSION}.linux-amd64.tar.gz
rm /go${GO_VERSION}.linux-amd64.tar.gz
EOT

ENV PATH="/usr/local/go/bin:${PATH}"

ENV INSTALL_DIR=/dist

COPY --from=build ${INSTALL_DIR} ${INSTALL_DIR}

ENV PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:${INSTALL_DIR}/lib/pkgconfig"

# Add gohs code

Expand Down

0 comments on commit b790463

Please sign in to comment.