ci.yml 1.99 KB
Newer Older
1
build:
2
3
4
5
6
7
    only:
        - master
        - tags
        - merge_requests
    stage: build
    image: maven:3-jdk-11
8
9
10
11
12
13
14
    script: mvn compile

test:
    only:
        - master
        - tags
        - merge_requests
femiadeyemi's avatar
femiadeyemi committed
15
    stage: test
16
    image: maven:3-jdk-11
17
18
    script:
        - 'export AAI_TOKEN=$(curl -u "helmholtz-marketplace:${CLIENT_SECRET}" -X POST "https://login.helmholtz.de/oauth2/token" -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=refresh_token&refresh_token=${AAI_REFRESH_TOKEN}&client_id=helmholtz-marketplace&client_secret=${CLIENT_SECRET}" | sed "s/{.*\"access_token\":\"\([^\"]*\).*}/\1/g")'
femiadeyemi's avatar
femiadeyemi committed
19
        - mvn -Dtoken=$AAI_TOKEN test
20
21
22
23
24
25
26
27
28

package:
    only:
        - master
    stage: package
    image: maven:3-jdk-11
    script: mvn -DskipTests clean install
    artifacts:
        paths:
femiadeyemi's avatar
femiadeyemi committed
29
            - "target/*.jar"
30
31
32
33
34
35
36
        expire_in: 600 seconds
    tags:
        - "docker"

docker_push:
    only:
        - master
37
        - tags
38
39
40
41
42
43
44
45
46
    stage: deploy
    image: docker:19.03.11
    services:
        - name: docker:19.03.11-dind
          alias: docker
    before_script:
        - docker info
    script:
        - docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
47
        - echo $CI_COMMIT_TAG
48
49
50
51
52
53
54
        - |-
            if [[ $CI_COMMIT_TAG == "" ]]; then
              docker build -t $DOCKER_IMAGE_LATEST .
              docker push $DOCKER_IMAGE_LATEST
            else
              docker build -t $DOCKER_IMAGE_TAGGED .
              docker push $DOCKER_IMAGE_TAGGED
femiadeyemi's avatar
femiadeyemi committed
55
            fi
56
57
58
    dependencies:
        - package
    tags:
femiadeyemi's avatar
femiadeyemi committed
59
        - "docker"
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

production_deployment:
    image: ubuntu
    only:
        - master
    stage: deploy
    before_script:
        - 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
        - eval $(ssh-agent -s)
        - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
        - mkdir -p ~/.ssh
        - chmod 700 ~/.ssh
    script:
        - ssh -A ubuntu@hifis-tp.desy.de
        - echo $(whoami)
        - exit