aboutsummaryrefslogtreecommitdiffstats
path: root/.drone.yml
blob: 3cda6d73617f6b1301d321ee2582fb001ecb860a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
---
kind: pipeline
type: docker
name: linting

steps:
  - name: gitleaks
    image: plugins/gitleaks
    settings:
      path: .
    when:
      event:
        exclude:
          - tag

  - name: hadolint
    image: hadolint/hadolint:latest-debian
    commands:
      - hadolint Dockerfile

---
kind: pipeline
type: docker
name: selfhosted
depends_on: # bezieht sich auf linting pipeline
  - linting
steps:
  - name: docker_build_and_push_selfhosted
    image: plugins/docker
    settings:
      dockerfile: Dockerfile
      repo: registry.mgrote.net/python-api-server
      registry: registry.mgrote.net
      tags:
        - ${DRONE_COMMIT_SHA:0:8}
        - ${DRONE_COMMIT_BRANCH}
        - latest
    when:
      event:
        exclude:
          - pull_request
          - tag

  - name: docker_build_and_push_selfhosted_tag
    image: plugins/docker
    settings:
      dockerfile: Dockerfile
      repo: registry.mgrote.net/python-api-server
      registry: registry.mgrote.net
      tags:
        - ${DRONE_TAG}
    when:
      event:
        - tag

---
kind: pipeline
type: docker
name: dockerhub
depends_on: # bezieht sich auf linting pipeline
  - linting
steps:
  - name: docker_build_and_push_dockerhub
    image: plugins/docker
    settings:
      username:
        from_secret: DOCKERHUB_USER
      password:
        from_secret: DOCKERHUB_PASS
      dockerfile: Dockerfile
      repo: quotengrote/python-api-server
      tags:
        - ${DRONE_COMMIT_SHA:0:8}
        - ${DRONE_COMMIT_BRANCH}
        - latest
    when:
      event:
        exclude:
          - pull_request
          - tag

  - name: docker_build_and_push_dockerhub_tag
    image: plugins/docker
    settings:
      username:
        from_secret: DOCKERHUB_USER
      password:
        from_secret: DOCKERHUB_PASS
      dockerfile: Dockerfile
      repo: quotengrote/python-api-server
      tags:
        - ${DRONE_TAG}
    when:
      event:
        - tag

---
kind: pipeline
type: docker
name: test
depends_on:
  - selfhosted
  - dockerhub

steps:
  - name: test
    image: registry.mgrote.net/python-api-server:latest
    environment:
      MAX_CONTENT_LENGTH: 50
      UPLOAD_DIRECTORY: /uploads
      AUTH_TOKEN: myuploadtoken
      ENABLE_WEBSERVER: false
      DEBIAN_FRONTEND: noninteractive
    commands:
      - |
        apt update
        apt install wget jq curl -y
        python3 -m gunicorn app:app c gunicorn_config.py &
        export TOKEN=myuploadtoken
        export URL="localhost:5000"
        mkdir -p tests
        echo "Test: normaler Upload"
        echo content > tests/file
        curl -X POST -H "token: $TOKEN" -F "file=@tests/file" $URL/upload | jq
        echo "Test: leerer Upload"
        curl -X POST -H "token: $TOKEN" $URL/upload | jq
        echo "Test: fehlerhafter Dateiname Upload"
        touch ./tests/'hallo\welt.txt'
        curl -X POST -H "token: $TOKEN" -F "file=@tests/hallo\welt.txt" $URL/upload | jq
        echo "Test: List Files"
        curl -H "token: $TOKEN" $URL/list | jq
        echo "Test: download Datei"
        wget $URL/download/file -o ./tests/file
        ls -lah ./tests/file
        echo "Test: download nicht vorhandene Datei"
        wget $URL/download/file2
        echo "Test: lösche Datei"
        curl -X DELETE -H "token: $TOKEN" $URL/delete/file | jq
        echo "Test: lösche nicht vorhandene Datei"
        curl -X DELETE -H "token: $TOKEN" $URL/delete/file2 | jq
        echo "Test: check health"
        curl $URL/health
        rm -rf tests