.gitlab-ci.yml 5.08 KB
Newer Older
1
2
default:
  image: "archlinux:latest"
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
3

4
stages:
5
  - lint
6
  - build
juadde's avatar
juadde committed
7
  - test
8
  - publish
9

Christian Rebischke's avatar
Christian Rebischke committed
10
shellcheck:
11
  stage: lint
12
13
  before_script:
    - pacman -Syu --needed --noconfirm shellcheck
Christian Rebischke's avatar
Christian Rebischke committed
14
  script:
15
16
    - shopt -s globstar
    - shellcheck **/*.sh
Christian Rebischke's avatar
Christian Rebischke committed
17
18

shfmt:
19
  stage: lint
20
21
  before_script:
    - pacman -Syu --needed --noconfirm shfmt
Christian Rebischke's avatar
Christian Rebischke committed
22
  script:
23
24
    - shopt -s globstar
    - shfmt -i 2 -ci -d **/*.sh
Christian Rebischke's avatar
Christian Rebischke committed
25

26
.build:
27
  stage: build
28
  before_script:
29
    - pacman -Syu --needed --noconfirm qemu-headless libisoburn
30
  script:
31
32
33
34
35
36
37
38
    - |
      # If we're building a tagged release, use the tag (without the 'v' prefix) as the
      # BUILD_VERSION. Otherwise, determine a new BUILD_VERSION.
      if [[ -n "$CI_COMMIT_TAG" ]]; then
        echo "BUILD_VERSION=${CI_COMMIT_TAG/v/}" > build.env
      else
        echo "BUILD_VERSION=$(date +%Y%m%d).$CI_JOB_ID" > build.env
      fi
39
40
    - export $(< build.env)
    - ./build-host.sh
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
41
  after_script:
Kristian Klausen's avatar
Kristian Klausen committed
42
    - echo "image_size_megabytes{image=\"basic\"} $(du -m output/*basic*qcow2)" > metrics.txt
43
    - echo "image_size_megabytes{image=\"cloudimg\"} $(du -m output/*cloudimg*qcow2)" > metrics.txt
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
44
45
46
    - echo "image_size_megabytes{image=\"libvirt\"} $(du -m output/*libvirt*box)" >> metrics.txt
    - echo "image_size_megabytes{image=\"virtualbox\"} $(du -m output/*virtualbox*box)" >> metrics.txt
  artifacts:
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
47
48
49
50
    name: "output"
    paths:
      - "output/*"
    expire_in: 2d
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
51
52
    reports:
      metrics: metrics.txt
53
      dotenv: build.env
54
55
56

build:
  extends: .build
57
58
  tags:
    - fast-single-thread
59
60
  except:
    - master
61
62
    - schedules
    - tags
63

64
build:secure:
65
66
67
68
69
  extends: .build
  tags:
    - secure
  only:
    - master
70
71
    - schedules
    - tags
72

juadde's avatar
juadde committed
73
74
75
76
77
78
79
80
test-vagrant-boxes-format:
  stage: test
  before_script:
    - pacman -Syu --needed --noconfirm vagrant
  script:
    - vagrant box add output/Arch-Linux-x86_64-virtualbox-*.box --name archlinux-vbox
    - vagrant box add output/Arch-Linux-x86_64-libvirt-*.box --name archlinux-libvirt

Kristian Klausen's avatar
Kristian Klausen committed
81
82
83
84
85
86
87
88
89
90
test-basic-qemu:
  stage: test
  variables:
    SSHPASS: arch
  before_script:
    - pacman -Syu --needed --noconfirm qemu-headless sshpass
  script:
    - qemu-system-x86_64 -m 512 -net nic -net user,hostfwd=tcp::2222-:22 -drive file=$(ls output/Arch-Linux-x86_64-basic-*.qcow2),if=virtio -nographic &
    - timeout 15m sh -c "while ! sshpass -e ssh -o ConnectTimeout=2 -o StrictHostKeyChecking=no arch@localhost -p 2222 sudo true; do sleep 1; done"

juadde's avatar
juadde committed
91
92
93
94
95
96
97
98
99
100
101
102
103
test-cloudimg-qemu:
  stage: test
  variables:
    SSHPASS: passw0rd
  before_script:
    - pacman -Syu --needed --noconfirm qemu-headless cdrtools sshpass
  script:
    - |
      cat > user-data <<EOF
      #cloud-config
      password: '${SSHPASS}'
      chpasswd: { expire: False }
      ssh_pwauth: True
104
105
106
107
108
109
110
      packages:
        - tmux
        - tree
      runcmd:
        - [ echo, 'Install more packages using runcmd.' ]
        - [ pacman, --noconfirm, -Syu, bat ]
        - [ touch, /runcmd_successful ]
juadde's avatar
juadde committed
111
112
113
114
115
116
117
118
119
120
      EOF
    - |
      cat > meta-data <<EOF
      instance-id: iid-local01
      local-hostname: cloudimg
      EOF
    - cat user-data meta-data
    - genisoimage -output seed.iso -volid cidata -joliet -rock user-data meta-data
    - qemu-system-x86_64 -m 512 -net nic -net user,hostfwd=tcp::2222-:22 -drive file=$(ls output/Arch-Linux-x86_64-cloudimg-*.qcow2),if=virtio -drive file=seed.iso,if=virtio -nographic &    
    - timeout 15m sh -c "while ! sshpass -e ssh -o ConnectTimeout=2 -o StrictHostKeyChecking=no arch@localhost -p 2222 true; do sleep 1; done"
121
122
    - timeout 15m sh -c "while ! sshpass -e ssh -o ConnectTimeout=2 -o StrictHostKeyChecking=no arch@localhost -p 2222 pacman -Q bat tmux tree; do sleep 1; done"
    - timeout 15m sh -c "while ! sshpass -e ssh -o ConnectTimeout=2 -o StrictHostKeyChecking=no arch@localhost -p 2222 test -f /runcmd_successful ; do sleep 1; done"
juadde's avatar
juadde committed
123

124
125
126
127
128
129
130
131
132
133
134
135
tag_release:
  stage: publish
  tags:
    - secure
  only:
    refs:
      - schedules
    variables:
      - $SCHEDULED_PUBLISH == "TRUE"
  before_script:
    - pacman -Syu --needed --noconfirm httpie
  script:
136
    - >
137
138
        export ASSET_LINKS="{ \"links\": [ \
          { \"name\": \"Vagrant Cloud Release\", \"url\": \"https://app.vagrantup.com/archlinux/boxes/archlinux/versions/$BUILD_VERSION\" }, \
139
          { \"name\": \"Browse artifacts\", \"url\": \"https://gitlab.archlinux.org/archlinux/arch-boxes/-/jobs/artifacts/v$BUILD_VERSION/browse/output?job=build:secure\" } \
140
        ]}"
141
142
143
144
145
    - http --ignore-stdin "$CI_API_V4_URL/projects/$CI_PROJECT_ID/releases"
        "JOB-TOKEN:$CI_JOB_TOKEN"
        "name=v$BUILD_VERSION"
        "tag_name=v$BUILD_VERSION"
        "ref=$CI_COMMIT_SHA"
146
        "assets:=$ASSET_LINKS"
147

148
149
150
publish:
  stage: publish
  tags:
151
    - secure
152
153
  only:
    - tags
154
  before_script:
155
    - pacman -Syu --needed --noconfirm vagrant
156
  script:
157
    - vagrant cloud auth login --token "${VAGRANT_API_TOKEN}"
158
159
    - vagrant cloud auth login --check
    - vagrant cloud box show archlinux/archlinux
Sven-Hendrik Haase's avatar
Sven-Hendrik Haase committed
160
161
    - vagrant cloud publish archlinux/archlinux "${BUILD_VERSION}" libvirt output/Arch-Linux-x86_64-libvirt-*.box --release -f
    - vagrant cloud publish archlinux/archlinux "${BUILD_VERSION}" virtualbox output/Arch-Linux-x86_64-virtualbox-*.box --release -f