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/workflows/test.yml | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .github/workflows/test.yml (limited to '.github/workflows/test.yml') 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 -- cgit v1.2.3-70-g09d2 From d245df360c1b1fe79f7720eb1a51142e31b19f26 Mon Sep 17 00:00:00 2001 From: Emiliano Ciavatta Date: Wed, 28 Jul 2021 10:29:20 +0200 Subject: Update test workflow --- .github/workflows/test.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to '.github/workflows/test.yml') diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f762ce2..dfbdef3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Build and Test +name: Test on: [push, pull_request] @@ -18,7 +18,7 @@ jobs: with: go-version: 1.16 - name: Install dependencies - run: apt-get install pkg-config libpcap-dev libhyperscan-dev + run: sudo 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 @@ -26,14 +26,15 @@ jobs: build_frontend: name: Build frontend runs-on: ubuntu-latest + defaults: + run: + working-directory: frontend 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 -- cgit v1.2.3-70-g09d2 From 1f40425b04f3c86ca8401942d66b1ad1739b472a Mon Sep 17 00:00:00 2001 From: Emiliano Ciavatta Date: Wed, 28 Jul 2021 11:23:40 +0200 Subject: Add deploy workflow. Update Dockerfile --- .github/workflows/deploy.yml | 38 ++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 2 -- .travis.yml | 22 ------------------- Dockerfile | 52 +++++++++++++++++++++++++++++--------------- docker-compose.yml | 12 ++++++---- 5 files changed, 80 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/deploy.yml delete mode 100644 .travis.yml (limited to '.github/workflows/test.yml') diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..38f302f --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,38 @@ +name: Deploy +on: + release: + types: + - published +env: + REGISTRY: ghcr.io + IMAGE_NAME: caronte +jobs: + build_push_docker: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v2 + - name: Log in to the Container registry + uses: docker/login-action@v1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract metadata for Docker + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Build and push Docker image + id: docker_build + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + - name: Image digests + run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dfbdef3..9f84ef3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,7 +1,5 @@ name: Test - on: [push, pull_request] - jobs: test_backend: name: Build and test backend diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b59b12f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,22 +0,0 @@ -language: bash - -sudo: required -services: - - docker - -before_script: - - docker pull mongo:4 - - docker-compose -f docker-compose.testing.yml up -d --build - -script: >- - docker ps -a && - docker logs -f $(docker ps -a -q --filter="name=caronte_caronte") | grep "travis" | - (read status; if [[ $status == "travis_tests_fails" ]]; then exit 1; fi) - -after_success: - - docker cp "$(docker ps -a -q --filter='name=caronte_caronte'):/caronte/coverage.txt" coverage.txt - - bash <(curl -s https://codecov.io/bash) - -after_script: - - docker logs $(docker ps -a -q --filter="name=caronte_caronte") - - docker-compose -f docker-compose.testing.yml down diff --git a/Dockerfile b/Dockerfile index a9c8134..4fb71a3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,38 +1,54 @@ -# BUILD STAGE -FROM ubuntu:20.04 AS BUILDSTAGE +# Build backend with go +FROM golang:1.16 AS BACKEND_BUILDER # Install tools and libraries RUN apt-get update && \ - DEBIAN_FRONTEND=noninteractive apt-get install -qq git golang-1.14 pkg-config libpcap-dev libhyperscan-dev yarnpkg - -COPY . /caronte + DEBIAN_FRONTEND=noninteractive apt-get install -qq \ + git \ + pkg-config \ + libpcap-dev \ + libhyperscan-dev WORKDIR /caronte -RUN ln -sf ../lib/go-1.14/bin/go /usr/bin/go && \ - export VERSION=$(git describe --tags) && \ +COPY . ./ + +RUN export VERSION=$(git describe --tags --abbrev=0) && \ go mod download && \ go build -ldflags "-X main.Version=$VERSION" && \ - cd frontend && \ - yarnpkg install && \ - yarnpkg build --production=true && \ - cd - && \ - mkdir -p /caronte-build/frontend && \ - cp -r caronte pcaps/ scripts/ shared/ test_data/ /caronte-build && \ - cp -r frontend/build/ /caronte-build/frontend + mkdir -p build && \ + cp -r caronte pcaps/ scripts/ shared/ test_data/ build/ + + +# Build frontend via yarn +FROM node:16 as FRONTEND_BUILDER + +WORKDIR /caronte-frontend + +COPY ./frontend ./ + +RUN yarnpkg install && yarnpkg build --production=true # LAST STAGE FROM ubuntu:20.04 -COPY --from=BUILDSTAGE /caronte-build /caronte +COPY --from=BACKEND_BUILDER /caronte/build /opt/caronte + +COPY --from=FRONTEND_BUILDER /caronte-frontend/build /opt/caronte/frontend/build RUN apt-get update && \ - DEBIAN_FRONTEND=noninteractive apt-get install -qq libpcap-dev libhyperscan-dev && \ + DEBIAN_FRONTEND=noninteractive apt-get install -qq \ + libpcap-dev \ + libhyperscan-dev && \ rm -rf /var/lib/apt/lists/* ENV GIN_MODE release -WORKDIR /caronte +ENV MONGO_HOST mongo + +ENV MONGO_PORT 27017 + +WORKDIR /opt/caronte -CMD ./caronte +ENTRYPOINT ./caronte -mongo-host ${MONGO_HOST} -mongo-port ${MONGO_PORT} -assembly_memuse_log diff --git a/docker-compose.yml b/docker-compose.yml index b43ec5b..484755a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,20 +2,24 @@ version: "3.7" services: mongo: - image: mongo:4 + image: mongo:4.4 networks: - acheronet - restart: always + restart: unless-stopped caronte: - image: eciavatta/caronte:latest + image: ghcr.io/eciavatta/caronte:latest + build: . ports: - "3333:3333" + environment: + MONGO_HOST: mongo + MONGO_PORT: 27017 depends_on: - mongo networks: - acheronet - command: ./caronte -mongo-host mongo -mongo-port 27017 -assembly_memuse_log + restart: unless-stopped networks: acheronet: -- cgit v1.2.3-70-g09d2 From bf6c04e4cc6438dea33a18a1c8bbdfce3876b86f Mon Sep 17 00:00:00 2001 From: Emiliano Ciavatta Date: Wed, 28 Jul 2021 11:50:08 +0200 Subject: Update docker tests --- .github/docker/Dockerfile | 18 ------------------ .github/docker/Dockerfile-backend | 18 ++++++++++++++++++ .github/docker/Dockerfile-frontend | 7 +++++++ .github/docker/docker-compose.yml | 12 +++++++++--- .github/workflows/test.yml | 6 ++++-- frontend/package.json | 5 +---- 6 files changed, 39 insertions(+), 27 deletions(-) delete mode 100644 .github/docker/Dockerfile create mode 100644 .github/docker/Dockerfile-backend create mode 100644 .github/docker/Dockerfile-frontend (limited to '.github/workflows/test.yml') diff --git a/.github/docker/Dockerfile b/.github/docker/Dockerfile deleted file mode 100644 index 1f9f72d..0000000 --- a/.github/docker/Dockerfile +++ /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 go test -v -race -covermode=atomic diff --git a/.github/docker/Dockerfile-backend b/.github/docker/Dockerfile-backend new file mode 100644 index 0000000..06036e4 --- /dev/null +++ b/.github/docker/Dockerfile-backend @@ -0,0 +1,18 @@ +FROM golang:1.16 + +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -qq \ + git \ + pkg-config \ + libpcap-dev \ + libhyperscan-dev + +WORKDIR /caronte + +COPY . ./ + +RUN export VERSION=$(git describe --tags --abbrev=0) && \ + go mod download && \ + go build -ldflags "-X main.Version=$VERSION" + +ENTRYPOINT go test -v -race -covermode=atomic diff --git a/.github/docker/Dockerfile-frontend b/.github/docker/Dockerfile-frontend new file mode 100644 index 0000000..5cd82b0 --- /dev/null +++ b/.github/docker/Dockerfile-frontend @@ -0,0 +1,7 @@ +FROM node:16 + +WORKDIR /caronte-frontend + +COPY ./frontend ./ + +RUN yarn install && yarn build diff --git a/.github/docker/docker-compose.yml b/.github/docker/docker-compose.yml index 393bb41..ddaf839 100644 --- a/.github/docker/docker-compose.yml +++ b/.github/docker/docker-compose.yml @@ -4,13 +4,19 @@ services: mongo: image: mongo:4.4 - test: + test-backend: build: context: ../../ - dockerfile: .github/docker/Dockerfile - image: caronte-test + dockerfile: .github/docker/Dockerfile-backend + image: caronte-test-backend depends_on: - mongo environment: MONGO_HOST: mongo MONGO_PORT: 27017 + + test-frontend: + build: + context: ../../ + dockerfile: .github/docker/Dockerfile-frontend + image: caronte-test-frontend diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9f84ef3..96d6a35 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -50,7 +50,9 @@ jobs: run: docker-compose build test - name: Start MongoDB run: docker-compose up -d mongo - - name: Run tests - run: docker-compose run test + - name: Test docker backend + run: docker-compose run test-backend + - name: Test docker frontend + run: docker-compose run test-frontend - name: Destroy containers run: docker-compose down diff --git a/frontend/package.json b/frontend/package.json index 82acb18..2190ebf 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -53,8 +53,5 @@ "last 1 safari version" ] }, - "license": "GPL-3.0", - "resolutions": { - "object-path": "0.11.5" - } + "license": "GPL-3.0" } -- cgit v1.2.3-70-g09d2 From c6b52a15fbbdbf4e9a089cc0b58fc82252d6f71b Mon Sep 17 00:00:00 2001 From: Emiliano Ciavatta Date: Wed, 28 Jul 2021 11:55:14 +0200 Subject: Update frontend dependencies --- .github/workflows/test.yml | 8 ++++---- frontend/yarn.lock | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to '.github/workflows/test.yml') diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 96d6a35..95b44fc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -46,13 +46,13 @@ jobs: - uses: actions/checkout@v2 - name: Pull docker images run: docker-compose pull mongo - - name: Build docker images - run: docker-compose build test + - name: Build docker backend + run: docker-compose build test-backend + - name: Build docker frontend + run: docker-compose build test-frontend - name: Start MongoDB run: docker-compose up -d mongo - name: Test docker backend run: docker-compose run test-backend - - name: Test docker frontend - run: docker-compose run test-frontend - name: Destroy containers run: docker-compose down diff --git a/frontend/yarn.lock b/frontend/yarn.lock index 5c437fc..22678f3 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -7827,10 +7827,10 @@ object-keys@^1.0.12, object-keys@^1.1.1: resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.1.1.tgz#1c47f272df277f3b1daf061677d9c82e2322c60e" integrity sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA== -object-path@0.11.4, object-path@0.11.5: - version "0.11.5" - resolved "https://registry.yarnpkg.com/object-path/-/object-path-0.11.5.tgz#d4e3cf19601a5140a55a16ad712019a9c50b577a" - integrity sha512-jgSbThcoR/s+XumvGMTMf81QVBmah+/Q7K7YduKeKVWL7N111unR2d6pZZarSk6kY/caeNxUDyxOvMWyzoU2eg== +object-path@0.11.4: + version "0.11.4" + resolved "https://registry.yarnpkg.com/object-path/-/object-path-0.11.4.tgz#370ae752fbf37de3ea70a861c23bba8915691949" + integrity sha1-NwrnUvvzfePqcKhhwju6iRVpGUk= object-visit@^1.0.0: version "1.0.1" -- cgit v1.2.3-70-g09d2