From 520901864877b7be3115e4fa0ee6544c3de2476c Mon Sep 17 00:00:00 2001 From: Emiliano Ciavatta Date: Wed, 28 Jul 2021 10:17:39 +0200 Subject: Add github test workflow --- .github/docker/Dockerfile | 18 +++++++++++++ .github/docker/docker-compose.yml | 16 +++++++++++ .github/workflows/test.yml | 57 +++++++++++++++++++++++++++++++++++++++ Dockerfile.testing | 18 ------------- docker-compose.testing.yml | 27 ------------------- scripts/travis_tests.sh | 18 ------------- 6 files changed, 91 insertions(+), 63 deletions(-) create mode 100644 .github/docker/Dockerfile create mode 100644 .github/docker/docker-compose.yml create mode 100644 .github/workflows/test.yml delete mode 100644 Dockerfile.testing delete mode 100644 docker-compose.testing.yml delete mode 100755 scripts/travis_tests.sh diff --git a/.github/docker/Dockerfile b/.github/docker/Dockerfile new file mode 100644 index 0000000..1f9f72d --- /dev/null +++ b/.github/docker/Dockerfile @@ -0,0 +1,18 @@ +FROM ubuntu:20.04 + +# Install tools and libraries +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -qq golang-1.14 pkg-config libpcap-dev libhyperscan-dev yarnpkg + +COPY ./ /caronte + +WORKDIR /caronte + +RUN ln -sf ../lib/go-1.14/bin/go /usr/bin/go && \ + go mod download && \ + go build && \ + cd frontend && \ + yarnpkg install && \ + yarnpkg build + +CMD go test -v -race -covermode=atomic diff --git a/.github/docker/docker-compose.yml b/.github/docker/docker-compose.yml new file mode 100644 index 0000000..393bb41 --- /dev/null +++ b/.github/docker/docker-compose.yml @@ -0,0 +1,16 @@ +version: "3.7" +services: + + mongo: + image: mongo:4.4 + + test: + build: + context: ../../ + dockerfile: .github/docker/Dockerfile + image: caronte-test + depends_on: + - mongo + environment: + MONGO_HOST: mongo + MONGO_PORT: 27017 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..f762ce2 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,57 @@ +name: Build and Test + +on: [push, pull_request] + +jobs: + test_backend: + name: Build and test backend + runs-on: ubuntu-latest + services: + mongo: + image: mongo:4.4 + ports: + - 27017:27017 + steps: + - uses: actions/checkout@v2 + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + - name: Install dependencies + run: apt-get install pkg-config libpcap-dev libhyperscan-dev + - name: Test backend + run: go test -v -race -coverprofile=coverage.txt -covermode=atomic + - name: Upload coverage + run: bash <(curl -s https://codecov.io/bash) + build_frontend: + name: Build frontend + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: 14.x + cache: 'yarn' + - run: cd frontend + - name: Install dependencies + run: yarn install + - name: Build frontend + run: yarn build + test_docker: + name: Build and test docker environment + runs-on: ubuntu-latest + env: + COMPOSE_FILE: .github/docker/docker-compose.yml + steps: + - uses: actions/checkout@v2 + - name: Pull docker images + run: docker-compose pull mongo + - name: Build docker images + run: docker-compose build test + - name: Start MongoDB + run: docker-compose up -d mongo + - name: Run tests + run: docker-compose run test + - name: Destroy containers + run: docker-compose down diff --git a/Dockerfile.testing b/Dockerfile.testing deleted file mode 100644 index 3498341..0000000 --- a/Dockerfile.testing +++ /dev/null @@ -1,18 +0,0 @@ -FROM ubuntu:20.04 - -# Install tools and libraries -RUN apt-get update && \ - DEBIAN_FRONTEND=noninteractive apt-get install -qq golang-1.14 pkg-config libpcap-dev libhyperscan-dev yarnpkg - -COPY . /caronte - -WORKDIR /caronte - -RUN ln -sf ../lib/go-1.14/bin/go /usr/bin/go && \ - go mod download && \ - go build && \ - cd frontend && \ - yarnpkg install && \ - yarnpkg build - -CMD ./caronte diff --git a/docker-compose.testing.yml b/docker-compose.testing.yml deleted file mode 100644 index 9d75af9..0000000 --- a/docker-compose.testing.yml +++ /dev/null @@ -1,27 +0,0 @@ -version: "3.7" -services: - - mongo: - image: mongo:4 - networks: - - acheronet - restart: always - - caronte: - build: - context: . - dockerfile: Dockerfile.testing - image: caronte - ports: - - "6666:6666" - depends_on: - - mongo - networks: - - acheronet - command: "./scripts/travis_tests.sh" - environment: - MONGO_HOST: mongo - MONGO_PORT: 27017 - -networks: - acheronet: diff --git a/scripts/travis_tests.sh b/scripts/travis_tests.sh deleted file mode 100755 index 5c51823..0000000 --- a/scripts/travis_tests.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -# wait mongodb server -sleep 10 - -# run tests -go test -v -race -coverprofile=coverage.txt -covermode=atomic - -RET_CODE=$? - -# -if [ $RET_CODE -eq 0 ]; then - echo "travis_tests_success" -else - echo "travis_tests_fails" -fi - -exit $RET_CODE -- cgit v1.2.3-70-g09d2