Skip to content

Commit

Permalink
Merge pull request #54 from flier/feature/upgrade_golang
Browse files Browse the repository at this point in the history
upgrade golang
  • Loading branch information
flier authored Apr 18, 2023
2 parents d02e941 + b790463 commit 6657c9a
Show file tree
Hide file tree
Showing 50 changed files with 628 additions and 985 deletions.
59 changes: 23 additions & 36 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
test:
strategy:
matrix:
os: [ubuntu-22.04, ubuntu-20.04, ubuntu-18.04, macos-12, macos-11]
go: [stable, 1.18.x, 1.17.x, 1.16.x, 1.15.x]
name: Go ${{ matrix.go }} tests @ ${{ matrix.os }} for hyperscan ${{ matrix.hyperscan }}
os: [ubuntu-22.04, ubuntu-20.04, macos-12, macos-11]
go: [stable, 1.20.x, 1.19.x, 1.18.x]
name: Go ${{ matrix.go }} tests @ ${{ matrix.os }} for hyperscan
runs-on: ${{ matrix.os }}
steps:
- name: Install Linux dependencies for testing libraries
Expand All @@ -37,19 +37,17 @@ jobs:
- uses: actions/checkout@v3

- name: Install Golang ${{ matrix.go }}
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
cache: true

- name: Test Hyperscan v4 API
if: matrix.os == 'ubuntu-18.04'
run: |
go test -v -tags hyperscan_v4 ./internal/hs/... ./hyperscan/...
go test -race -v -tags hyperscan_v4 ./internal/hs/... ./hyperscan/...
- name: Test Hyperscan v5 API
if: matrix.os != 'ubuntu-18.04'
run: |
go test -v ./internal/hs/... ./hyperscan/...
go test -race -v ./internal/hs/... ./hyperscan/...
Expand All @@ -60,47 +58,36 @@ jobs:
include:
- os: macos-latest
go: stable
hyperscan: 5.4.0
pcre: 8.45
hyperscan_version: 5.4.1
pcre_version: 8.45
build_flags: -tags hyperscan_v54,chimera
chimera: true
- os: macos-latest
- os: macos-12
go: stable
hyperscan: 5.2.1
pcre: 8.45
hyperscan_version: 5.2.1
pcre_version: 8.45
build_flags: -tags hyperscan_v52,chimera
chimera: true
- os: macos-latest
- os: macos-11
go: stable
hyperscan: 5.1.1
pcre: 8.45
hyperscan_version: 5.1.1
pcre_version: 8.45
build_flags: -tags chimera
chimera: true
- os: ubuntu-20.04
- os: ubuntu-22.04
go: stable
hyperscan: 5.4.0
pcre: 8.45
hyperscan_version: 5.4.1
pcre_version: 8.45
build_flags: -tags hyperscan_v54,chimera
chimera: true
coverage: true
- os: ubuntu-20.04
go: stable
hyperscan: 5.2.1
pcre: 8.45
hyperscan_version: 5.2.1
pcre_version: 8.45
build_flags: -tags hyperscan_v52,chimera
chimera: true
- os: ubuntu-20.04
go: stable
hyperscan: 5.1.1
pcre: 8.45
build_flags: -tags chimera
chimera: true
- os: ubuntu-18.04
go: stable
hyperscan: 4.7.0
pcre: 8.41
build_flags: -tags hyperscan_v4
name: Go ${{ matrix.go }} tests @ ${{ matrix.os }} for hyperscan ${{ matrix.hyperscan }}
name: Go ${{ matrix.go }} tests @ ${{ matrix.os }} for hyperscan ${{ matrix.hyperscan_version }}
runs-on: ${{ matrix.os }}
env:
PKG_CONFIG_PATH: ${{ github.workspace }}/dist/lib/pkgconfig
Expand All @@ -109,15 +96,15 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Install Hyperscan ${{ matrix.hyperscan }} with PCRE ${{ matrix.pcre }}
- name: Install Hyperscan ${{ matrix.hyperscan }} with PCRE ${{ matrix.pcre_version }}
uses: flier/install-hyperscan@main
with:
hyperscan_version: ${{ matrix.hyperscan }}
pcre_version: ${{ matrix.pcre }}
hyperscan_version: ${{ matrix.hyperscan_version }}
pcre_version: ${{ matrix.pcre_version }}
build_static_lib: on
src_dir: ${{ runner.temp }}/hyperscan/
install_prefix: ${{ github.workspace }}/dist/
cache_key: ${{ runner.os }}-build-hyperscan-${{ matrix.hyperscan }}-pcre-${{ matrix.pcre }}
cache_key: ${{ runner.os }}-build-hyperscan-${{ matrix.hyperscan_version }}-pcre-${{ matrix.pcre_version }}

- name: Install Golang ${{ matrix.go }}
uses: actions/setup-go@v3
Expand Down Expand Up @@ -146,7 +133,7 @@ jobs:
golangci:
name: lint
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Install Linux dependencies
run: |
Expand Down
65 changes: 65 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: docker

on:
push:
branches:
- master
paths-ignore:
- "**.md"
pull_request:
paths-ignore:
- "**.md"

jobs:
docker:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- 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:
- name: Checkout
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: Build and push
uses: docker/build-push-action@v4
with:
load: true
build-args: |
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
run: |
docker run --rm ${{ env.LATEST_TAG }} test ${{ matrix.build_flags }} -v ./...
131 changes: 93 additions & 38 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,61 +1,116 @@
ARG UBUNTU_VERSION=20.04
# syntax=docker/dockerfile:1

FROM ubuntu:${UBUNTU_VERSION}
ARG UBUNTU_VERSION=22.04

ARG GO_VERSION=1.17.1
ARG HYPERSCAN_VERSION=5.4.0
ARG PCRE_VERSION=8.45
FROM ubuntu:${UBUNTU_VERSION} as build

# Install dependencies

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
cmake \
libboost-dev \
libbz2-dev \
libpcap-dev \
ninja-build \
pkg-config \
python2.7 \
ragel \
wget \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*

# Install golang

RUN wget https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz -O /go${GO_VERSION}.tar.gz && \
rm -rf /usr/local/go && \
tar -C /usr/local -xzf /go${GO_VERSION}.tar.gz && \
rm /go${GO_VERSION}.tar.gz

ENV PATH=/usr/local/go/bin:${PATH}
# hadolint ignore=DL3008
RUN <<EOT bash
apt-get update
apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
cmake \
libboost-dev \
libbz2-dev \
libpcap-dev \
ninja-build \
pkg-config \
python2.7 \
ragel \
wget \
zlib1g-dev
rm -rf /var/lib/apt/lists/*
EOT

# Download Hyperscan

ARG HYPERSCAN_VERSION=5.4.1

ENV HYPERSCAN_DIR=/hyperscan

RUN wget https://github.com/intel/hyperscan/archive/refs/tags/v${HYPERSCAN_VERSION}.tar.gz -O /hyperscan-${HYPERSCAN_VERSION}.tar.gz && \
mkdir ${HYPERSCAN_DIR} && tar xf /hyperscan-${HYPERSCAN_VERSION}.tar.gz -C ${HYPERSCAN_DIR} --strip-components=1 && rm /hyperscan-${HYPERSCAN_VERSION}.tar.gz
RUN wget https://sourceforge.net/projects/pcre/files/pcre/${PCRE_VERSION}/pcre-${PCRE_VERSION}.tar.gz/download -O /pcre-${PCRE_VERSION}.tar.gz && \
mkdir ${HYPERSCAN_DIR}/pcre && tar xf /pcre-${PCRE_VERSION}.tar.gz -C ${HYPERSCAN_DIR}/pcre --strip-components=1 && rm /pcre-${PCRE_VERSION}.tar.gz
WORKDIR ${HYPERSCAN_DIR}

ADD https://github.com/intel/hyperscan/archive/refs/tags/v${HYPERSCAN_VERSION}.tar.gz /hyperscan-v${HYPERSCAN_VERSION}.tar.gz
RUN <<EOT bash
tar xf /hyperscan-v${HYPERSCAN_VERSION}.tar.gz -C ${HYPERSCAN_DIR} --strip-components=1
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

RUN <<EOT bash
tar xf /pcre-${PCRE_VERSION}.tar.gz -C ${HYPERSCAN_DIR}/pcre --strip-components=1
rm /pcre-${PCRE_VERSION}.tar.gz
EOT

# Install Hyperscan

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

WORKDIR ${HYPERSCAN_DIR}/build

ARG CMAKE_BUILD_TYPE=RelWithDebInfo

RUN <<EOT bash
cmake -G Ninja \
-DBUILD_STATIC_LIBS=ON \
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \
-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} \
..
ninja
ninja install
mv ${HYPERSCAN_DIR}/build/lib/lib*.a ${INSTALL_DIR}/lib/
EOT

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

RUN mkdir ${HYPERSCAN_DIR}/build && cd ${HYPERSCAN_DIR}/build && \
cmake -G Ninja -DBUILD_STATIC_LIBS=on -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${INSTALL_DIR} ${HYPERSCAN_DIR} && \
ninja && ninja install && mv ${HYPERSCAN_DIR}/build/lib/lib*.a ${INSTALL_DIR}/lib/ && cd / && rm -rf ${HYPERSCAN_DIR}
COPY --from=build ${INSTALL_DIR} ${INSTALL_DIR}

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

# Add gohs code

ADD . /gohs/
COPY . /gohs/

WORKDIR /gohs
ENTRYPOINT ["/usr/local/go/bin/go"]
CMD ["test", "./..."]
CMD ["test", "-v", "./..."]
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
labels:
hyperscan: 5.4
args:
HYPERSCAN_VERSION: 5.4.0
HYPERSCAN_VERSION: 5.4.1
command: test -tags hyperscan_v54 ./...
hyperscan-5.2:
build:
Expand Down
13 changes: 8 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
module github.com/flier/gohs

go 1.15
go 1.18

require (
github.com/google/gopacket v1.1.19
github.com/smartystreets/goconvey v1.8.0
)

require (
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/smartystreets/assertions v1.13.0 // indirect
github.com/smartystreets/goconvey v1.7.2
golang.org/x/net v0.4.0 // indirect
golang.org/x/sys v0.3.0 // indirect
github.com/smartystreets/assertions v1.13.1 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sys v0.7.0 // indirect
)
Loading

0 comments on commit 6657c9a

Please sign in to comment.