Skip to content

Commit

Permalink
refactor: using docker to execute CI tests on Github actions to preve…
Browse files Browse the repository at this point in the history
…nt environmental breaking changes (#98)
  • Loading branch information
Yeuoly authored Oct 16, 2024
1 parent ebfc8ce commit 3e39e12
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 124 deletions.
58 changes: 0 additions & 58 deletions .github/workflows/tests-amd64.yml

This file was deleted.

60 changes: 0 additions & 60 deletions .github/workflows/tests-arm64.yml

This file was deleted.

35 changes: 35 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Run GoTest

on:
pull_request:
branches:
- main
push:
branches:
- main

concurrency:
group: test-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
test:
name: Test
runs-on: ${{ matrix.arch == 'amd64' && 'ubuntu-latest' || 'arm64_runner' }}
strategy:
matrix:
arch: [amd64, arm64]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Build and run tests
run: |
if [ "${{ matrix.arch }}" == "amd64" ]; then
docker build -t test -f docker/amd64-test/dockerfile .
docker run --rm test
elif [ "${{ matrix.arch }}" == "arm64" ]; then
docker build -t test -f docker/arm64-test/dockerfile .
docker run --rm test
fi
64 changes: 64 additions & 0 deletions docker/amd64-test/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
FROM golang:1.20.6 AS builder

COPY . /app
WORKDIR /app

# if you located in China, you can use aliyun mirror to speed up
# && echo "deb http://mirrors.aliyun.com/debian testing main" > /etc/apt/sources.list

# install dependencies and build binary
RUN apt-get update && apt-get install -y pkg-config gcc libseccomp-dev && go mod tidy && bash ./build/build_amd64.sh

FROM python:3.10-slim-bookworm as tester

# if you located in China, you can use aliyun mirror to speed up
# && echo "deb http://mirrors.aliyun.com/debian testing main" > /etc/apt/sources.list

# install system dependencies
RUN echo "deb http://deb.debian.org/debian testing main" > /etc/apt/sources.list \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
pkg-config \
libseccomp-dev \
wget \
curl \
xz-utils \
zlib1g=1:1.3.dfsg+really1.3.1-1 \
expat=2.6.3-1 \
perl=5.38.2-5 \
libsqlite3-0=3.46.0-1 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# workdir
WORKDIR /app

# checkout
COPY . /app

# copy binary and env from builder
COPY --from=builder /app/internal/core/runner/python/python.so /app/internal/core/runner/python/python.so
COPY --from=builder /app/internal/core/runner/nodejs/nodejs.so /app/internal/core/runner/nodejs/nodejs.so

# copy test config file
COPY conf/config.yaml /conf/config.yaml
# copy python dependencies
COPY dependencies/python-requirements.txt /dependencies/python-requirements.txt

# install python dependencies
RUN pip3 install --no-cache-dir httpx==0.27.2 requests==2.32.3 jinja2==3.0.3 PySocks httpx[socks]

# install node
RUN wget -O /opt/node-v20.11.1-linux-x64.tar.xz https://npmmirror.com/mirrors/node/v20.11.1/node-v20.11.1-linux-x64.tar.xz \
&& tar -xvf /opt/node-v20.11.1-linux-x64.tar.xz -C /opt \
&& ln -s /opt/node-v20.11.1-linux-x64/bin/node /usr/local/bin/node \
&& rm -f /opt/node-v20.11.1-linux-x64.tar.xz

# install golang 1.20.6
RUN wget https://golang.org/dl/go1.20.6.linux-amd64.tar.gz \
&& tar -C /usr/local -xzf go1.20.6.linux-amd64.tar.gz \
&& ln -s /usr/local/go/bin/go /usr/local/bin/go \
&& rm -f go1.20.6.linux-amd64.tar.gz

# run test
RUN go test -timeout 120s -v ./tests/integration_tests/...
2 changes: 1 addition & 1 deletion docker/amd64/dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ COPY conf/config.yaml /conf/config.yaml
COPY dependencies/python-requirements.txt /dependencies/python-requirements.txt

RUN chmod +x /main /env \
&& pip3 install --no-cache-dir jinja2 requests httpx PySocks httpx[socks] \
&& pip3 install --no-cache-dir httpx==0.27.2 requests==2.32.3 jinja2==3.0.3 PySocks httpx[socks] \
&& wget -O /opt/node-v20.11.1-linux-x64.tar.xz https://npmmirror.com/mirrors/node/v20.11.1/node-v20.11.1-linux-x64.tar.xz \
&& tar -xvf /opt/node-v20.11.1-linux-x64.tar.xz -C /opt \
&& ln -s /opt/node-v20.11.1-linux-x64/bin/node /usr/local/bin/node \
Expand Down
64 changes: 64 additions & 0 deletions docker/arm64-test/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
FROM golang:1.20.6 AS builder

COPY . /app
WORKDIR /app

# if you located in China, you can use aliyun mirror to speed up
# && echo "deb http://mirrors.aliyun.com/debian testing main" > /etc/apt/sources.list

# install dependencies and build binary
RUN apt-get update && apt-get install -y pkg-config gcc libseccomp-dev && go mod tidy && bash ./build/build_arm64.sh

FROM python:3.10-slim-bookworm as tester

# if you located in China, you can use aliyun mirror to speed up
# && echo "deb http://mirrors.aliyun.com/debian testing main" > /etc/apt/sources.list

# install system dependencies
RUN echo "deb http://deb.debian.org/debian testing main" > /etc/apt/sources.list \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
pkg-config \
libseccomp-dev \
wget \
curl \
xz-utils \
zlib1g=1:1.3.dfsg+really1.3.1-1 \
expat=2.6.3-1 \
perl=5.38.2-5 \
libsqlite3-0=3.46.0-1 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# workdir
WORKDIR /app

# checkout
COPY . /app

# copy binary and env from builder
COPY --from=builder /app/internal/core/runner/python/python.so /app/internal/core/runner/python/python.so
COPY --from=builder /app/internal/core/runner/nodejs/nodejs.so /app/internal/core/runner/nodejs/nodejs.so

# copy test config file
COPY conf/config.yaml /conf/config.yaml
# copy python dependencies
COPY dependencies/python-requirements.txt /dependencies/python-requirements.txt

# install python dependencies
RUN pip3 install --no-cache-dir httpx==0.27.2 requests==2.32.3 jinja2==3.0.3 PySocks httpx[socks]

# install node
RUN wget -O /opt/node-v20.11.1-linux-arm64.tar.xz https://npmmirror.com/mirrors/node/v20.11.1/node-v20.11.1-linux-arm64.tar.xz \
&& tar -xvf /opt/node-v20.11.1-linux-arm64.tar.xz -C /opt \
&& ln -s /opt/node-v20.11.1-linux-arm64/bin/node /usr/local/bin/node \
&& rm -f /opt/node-v20.11.1-linux-arm64.tar.xz

# install golang 1.20.6
RUN wget https://golang.org/dl/go1.20.6.linux-arm64.tar.gz \
&& tar -C /usr/local -xzf go1.20.6.linux-arm64.tar.gz \
&& ln -s /usr/local/go/bin/go /usr/local/bin/go \
&& rm -f go1.20.6.linux-arm64.tar.gz

# run test
RUN go test -timeout 120s -v ./tests/integration_tests/...
6 changes: 3 additions & 3 deletions docker/arm64/dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM python:3.10-slim-bookworm
# && echo "deb http://mirrors.aliyun.com/debian testing main" > /etc/apt/sources.list
RUN echo "deb http://deb.debian.org/debian testing main" > /etc/apt/sources.list \
&& apt-get update \
&& apt-get install -y --no-install-recommends
&& apt-get install -y --no-install-recommends \
pkg-config \
libseccomp-dev \
wget \
Expand All @@ -14,7 +14,7 @@ RUN echo "deb http://deb.debian.org/debian testing main" > /etc/apt/sources.list
expat=2.6.3-1 \
perl=5.38.2-5 \
libsqlite3-0=3.46.0-1 \
&& apt-get clean
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# copy main binary to /main
Expand All @@ -28,7 +28,7 @@ COPY conf/config.yaml /conf/config.yaml
COPY dependencies/python-requirements.txt /dependencies/python-requirements.txt

RUN chmod +x /main /env \
&& pip3 install --no-cache-dir jinja2 requests httpx PySocks httpx[socks] \
&& pip3 install --no-cache-dir httpx==0.27.2 requests==2.32.3 jinja2==3.0.3 PySocks httpx[socks] \
&& wget -O /opt/node-v20.11.1-linux-arm64.tar.xz https://npmmirror.com/mirrors/node/v20.11.1/node-v20.11.1-linux-arm64.tar.xz \
&& tar -xvf /opt/node-v20.11.1-linux-arm64.tar.xz -C /opt \
&& ln -s /opt/node-v20.11.1-linux-arm64/bin/node /usr/local/bin/node \
Expand Down
2 changes: 0 additions & 2 deletions tests/integration_tests/conf/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ python_lib_path:
- "/usr/local/lib/python3.10"
- "/usr/lib/python3.10"
- "/usr/lib/python3"
- "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10"
- "/opt/hostedtoolcache/Python/3.10.15/arm64/lib/python3.10"
- "/usr/lib/x86_64-linux-gnu"
- "/usr/lib/aarch64-linux-gnu"
- "/etc/ssl/certs/ca-certificates.crt"
Expand Down

0 comments on commit 3e39e12

Please sign in to comment.