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 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