stages:
  - build
  - upload
  - test

compile:
  stage: build
  image: golang:alpine
  script:
    - source ./env
    - go build -tags "$TAGS" -ldflags "$LDFLAGS" ./cmd/hepto.go
  artifacts:
    paths:
      - hepto
    expire_in: 1 week
  variables:
    GOPATH: $CI_PROJECT_DIR/.go
  before_script:
    - apk add --no-cache git gcc g++ libseccomp-dev libseccomp-static
    - git fetch --tags
    - mkdir -p .go
  cache:
    paths:
      - .go/pkg/mod/

.before_script_template: &setup-ansible
  before_script:
    - apk --no-cache add openssh-client
    - echo "$VAULT_PASSWORD" > /tmp/vault
    - eval $(ssh-agent -s)
    - ssh-add <(echo "$SSH_KEY"|base64 -d)
    - pip install ansible boto3 netaddr
  
variables:
  ANSIBLE_ARGS: -i .ansible-ci.yaml --vault-password-file /tmp/vault -e node_prefix=ci-$CI_JOB_ID

upload:
  stage: upload
  image: python:alpine
  <<: *setup-ansible
  script:
    - ansible $ANSIBLE_ARGS -m include_tasks -a file=ansible/ciupload.yaml localhost
  
test:
  stage: test
  image: python:alpine
  <<: *setup-ansible
  parallel:
    matrix:
      - PROVIDER: scaleway
        IMAGE:
        - debian12
      - PROVIDER: hetzner
        IMAGE:
        - debian12
  script:
    - ansible-playbook $ANSIBLE_ARGS ansible/cloud.yaml -e cloud_provider=$PROVIDER -e image=$IMAGE
    - ansible-playbook $ANSIBLE_ARGS ansible/test_podinfo.yaml
  after_script:
    - ansible-playbook $ANSIBLE_ARGS ansible/cleanup.yaml

 
