image: hello-world:latest

stages:
  - build-img
  - test

variables:
  CONAN_LOGIN_USERNAME: ci_user
  CONAN_PASSWORD: ${CI_JOB_TOKEN}
  REPO: gitlab

build-img:
  stage: build-img
  image:
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  script:
    - mkdir -p /kaniko/.docker
    - echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
    - /kaniko/executor --cache=true --context $CI_PROJECT_DIR --dockerfile ./Dockerfile --destination $CI_REGISTRY_IMAGE:latest
  tags:
    - docker


.package: &package_template
  stage: test
  image: $CI_REGISTRY_IMAGE:latest
  needs: ['build-img']
  script:
    - GIT_SHA=$(git rev-parse HEAD)
    - conan create . exa/stable -s compiler=${COMPILER} -s compiler.version=${CVERSION} -s compiler.libcxx=${LIBCXX}
    - conan remote add ${REPO} ${CI_API_V4_URL}/projects/$CI_PROJECT_ID/packages/conan
    - conan upload csg-eb/${GIT_SHA}@exa/stable --all --remote=${REPO}
  tags:
    - docker


package:gcc:
  variables:
    COMPILER: gcc
    CVERSION: 9
    LIBCXX: libstdc++
  <<: *package_template
