variables:
  CONTAINER_PROD_IMAGE_ARM: $HUB_REGISTRY_IMAGE:$CI_COMMIT_BRANCH-arm
  CONTAINER_BUILD_NOPROD_NAME_ARM: $HUB_REGISTRY_IMAGE:build-noprod-arm

docker-hub-build-arm:
  stage: Docker-hub-build
  image: docker:dind 
  dependencies:
    - package:debarm
  variables:
    DOCKER_DST: "/tmp/e2guardian/scripts/debian_package/e2debian_package"
    PROJECT_DIR: "$CI_PROJECT_DIR"
  before_script:
    - docker login -u "$DOCKER_HUB_USER" -p "$DOCKER_HUB_TOKEN" $DOCKER_HUB_REGISTRY
  script:
    - cd $PROJECT_DIR  
    - docker build --build-arg E2_VERSION="$CI_COMMIT_BRANCH" --build-arg PROJECT_DIR="$PROJECT_DIR" -f gitlabci/docker-ci/Dockerfile --pull -t $CONTAINER_BUILD_NOPROD_NAME_ARM .
    - docker push $CONTAINER_BUILD_NOPROD_NAME_ARM
  tags:
    - arm

docker-hub-test-arm:
  image: 
    name: $CONTAINER_BUILD_NOPROD_NAME_ARM
    entrypoint: [""]
  stage: Docker-hub-test
  dependencies: []
  script:
    - e2guardian -N &
    - sleep 5 && export https_proxy=http://localhost:8080 && curl -k https://www.google.fr
  tags:
    - arm

# Working on amd64 only
dive-arm:
  image:
    name: wagoodman/dive:latest
    entrypoint: [""]
  dependencies: []
  stage: Docker-hub-test
  script:
    - docker pull $CONTAINER_BUILD_NOPROD_NAME_ARM
    - dive $CONTAINER_BUILD_NOPROD_NAME_ARM
  variables:
    CI: "true"

push-docker-hub-arm:
  stage: Docker-hub-pushtag
  image: docker:dind
  dependencies: []
  before_script:
    - docker login -u "$DOCKER_HUB_USER" -p "$DOCKER_HUB_TOKEN" $DOCKER_HUB_REGISTRY
  script:
    - docker pull $CONTAINER_BUILD_NOPROD_NAME_ARM
    - docker tag $CONTAINER_BUILD_NOPROD_NAME_ARM $CONTAINER_PROD_IMAGE_ARM
    - docker push $CONTAINER_PROD_IMAGE_ARM
  tags:
    - arm
