version: "3"

services:

  runtime-setup:
    image: netty:default
    build:
      context: .
      dockerfile: Dockerfile.centos

  common: &common
    image: netty:default
    depends_on: [runtime-setup]
    volumes:
      - ~/.ssh:/root/.ssh:delegated
      - ~/.gnupg:/root/.gnupg:delegated
      - ..:/code:delegated
    working_dir: /code

  test-leak:
    <<: *common
    command: /bin/bash -cl "./mvnw -Pleak clean install -Dio.netty.testsuite.badHost=netty.io -Dmaven.wagon.http.pool=false"

  test:
    <<: *common
    command: /bin/bash -cl "./mvnw clean install -Dio.netty.testsuite.badHost=netty.io -Dmaven.wagon.http.pool=false"

  test-boringssl-static:
    <<: *common
    command: /bin/bash -cl "./mvnw -P boringssl clean install -Dio.netty.testsuite.badHost=netty.io -Dxml.skip=true -Dmaven.wagon.http.pool=false"

  shell:
    <<: *common
    environment:
      - SANOTYPE_USER
      - SANOTYPE_PASSWORD
    volumes:
      - ~/.ssh:/root/.ssh:delegated
      - ~/.gnupg:/root/.gnupg:delegated
      - ..:/code:delegated
      - ~/.m2:/root/.m2:delegated
    entrypoint: /bin/bash

  cross-compile-aarch64-runtime-setup:
    image: netty:cross_compile_aarch64
    build:
      context: .
      dockerfile: Dockerfile.cross_compile_aarch64
      args:
        gcc_version : "4.9-2016.02"

  cross-compile-aarch64:
    image: netty:cross_compile_aarch64
    depends_on: [cross-compile-aarch64-runtime-setup]
    volumes:
      - ~/.ssh:/root/.ssh:delegated
      - ~/.gnupg:/root/.gnupg:delegated
      - ..:/code:delegated
      - ~/.m2:/root/.m2:delegated
    # Since we are cross compiling netty-transport-native-epoll as aarch64 which cannot be loaded on x86_64, we add `skipTests` here to skip the test.
    command: /bin/bash -cl "pushd ./transport-native-unix-common && ../mvnw clean install -Plinux-aarch64 && popd && pushd ./transport-native-epoll && ../mvnw clean install -Plinux-aarch64 -DskipTests && popd"
    working_dir: /code