.gitlab-ci.yml 1.55 KB
Newer Older
Luke Texon's avatar
Luke Texon committed
1
stages:
2
        - build_docker
Luke Texon's avatar
Luke Texon committed
3
        - build
Matej Genci's avatar
Matej Genci committed
4
        - test
Luke Texon's avatar
Luke Texon committed
5 6
        - staging
        - production
Luke Texon's avatar
Luke Texon committed
7

8
variables:
Luke Texon's avatar
Luke Texon committed
9 10
        PORT: 5000      
        DOCKER_IMAGE: $CI_REGISTRY_IMAGE
11 12 13 14
        DOCKER_IMAGE_LATEST: $CI_REGISTRY_IMAGE:latest

build docker:   
        stage: build_docker
Luke Texon's avatar
Luke Texon committed
15 16
        tags: 
                - ljt18_webapp
17
        script:
18
                - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
Luke Texon's avatar
Luke Texon committed
19
                - docker system prune -f 
20
                - docker build -t $DOCKER_IMAGE .
Luke Texon's avatar
Luke Texon committed
21
                - docker push $DOCKER_IMAGE
22

23
compile java:
Luke Texon's avatar
Luke Texon committed
24
        stage: build
Luke Texon's avatar
Luke Texon committed
25
        image: $DOCKER_IMAGE_LATEST 
26
        script: mvn compile
27

28
testing:
Luke Texon's avatar
Luke Texon committed
29
        stage: test
Luke Texon's avatar
Luke Texon committed
30
        image: $DOCKER_IMAGE_LATEST 
31
        script: mvn test
Luke Texon's avatar
Luke Texon committed
32 33

deploy to vm:
34
        stage: staging       
Luke Texon's avatar
Luke Texon committed
35 36
        tags: 
                - ljt18_webapp 
37
        before_script:
Luke Texon's avatar
Luke Texon committed
38 39
                - docker stop vm_container || echo "Container not running"
                - docker rm vm_container || echo "Container not found"
Luke Texon's avatar
Luke Texon committed
40
        script:
Luke Texon's avatar
Luke Texon committed
41
                - docker run --name vm_container -d -e PORT=8080 -p $PORT:8080 $DOCKER_IMAGE_LATEST "mvn -Dmaven.test.skip=true package; sh target/bin/simplewebapp"
Luke Texon's avatar
Luke Texon committed
42 43 44 45 46 47
        environment: 
                name: VM
                url: http://$IP:$PORT

deploy to heroku: 
        stage: production
Luke Texon's avatar
Luke Texon committed
48
        image: $DOCKER_IMAGE_LATEST 
49
        script: dpl --provider=heroku --app=ljt18-simplewebapp --api-key=$API_KEY
Luke Texon's avatar
Luke Texon committed
50 51 52
        environment: 
                name: Heroku
                url: https://ljt18-simplewebapp.herokuapp.com/
53
        when: manual
Luke Texon's avatar
Luke Texon committed
54