stages:
  - build

golang:
  stage: build
  tags:
    - gobuild
  only:
    changes:
      - golang/Dockerfile
  before_script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
  script:
    - docker build -t $CI_REGISTRY_IMAGE/golang:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID $CI_PROJECT_DIR/golang
    - docker push $CI_REGISTRY_IMAGE/golang:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID
  after_script:
    - docker system prune --all --volumes --force

alpine:
  stage: build
  tags:
    - gobuild
  only:
    changes:
      - alpine/Dockerfile
  before_script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
  script:
    - docker build -t $CI_REGISTRY_IMAGE/alpine:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID $CI_PROJECT_DIR/alpine
    - docker push $CI_REGISTRY_IMAGE/alpine:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID
  after_script:
    - docker system prune --all --volumes --force

golint:
  stage: build
  tags:
    - gobuild
  only:
    changes:
      - golint/Dockerfile
      - golint/golangci-lint
  before_script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
  script:
    - docker build -t $CI_REGISTRY_IMAGE/golint:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID $CI_PROJECT_DIR/golint
    - docker push $CI_REGISTRY_IMAGE/golint:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID
  after_script:
    - docker system prune --all --volumes --force
