about summary refs log tree commit diff
path: root/tools/nixery/.travis.yml
blob: fcf2034d4472888b0e974ca9a0789a4a7b7fa34a (plain) (blame)
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
language: nix
arch:
  - amd64
  - arm64
services:
  - docker
env:
  - NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/0a40a3999eb4d577418515da842a2622a64880c5.tar.gz
before_script:
  - echo "Running Nixery CI build on $(uname -m)"
  - mkdir test-files
  - echo ${GOOGLE_KEY} | base64 -d > test-files/key.json
  - echo ${GCS_SIGNING_PEM} | base64 -d > test-files/gcs.pem
  - nix-env -f '<nixpkgs>' -iA -A go
script:
  - test -z $(gofmt -l server/ build-image/)
  - nix-build --arg maxLayers 2

  # This integration test makes sure that the container image built
  # for Nixery itself runs fine in Docker, and that images pulled
  # from it work in Docker.
  #
  # Output from the Nixery container is printed at the end of the
  # test regardless of test status.
  - IMG=$(docker load -q -i $(nix-build -A nixery-image) | awk '{ print $3 }')
  - echo "Loaded Nixery image as ${IMG}"

  - |
    docker run -d -p 8080:8080 --name nixery \
      -v ${PWD}/test-files:/var/nixery \
      -e PORT=8080 \
      -e GCS_BUCKET=nixery-ci-tests \
      -e GOOGLE_CLOUD_PROJECT=nixery \
      -e GOOGLE_APPLICATION_CREDENTIALS=/var/nixery/key.json \
      -e NIXERY_CHANNEL=nixos-unstable \
      -e NIXERY_STORAGE_BACKEND=gcs \
      ${IMG}

  # print all of the container's logs regardless of success
  - |
    function print_logs {
      echo "Nixery container logs:"
      docker logs nixery
    }
    trap print_logs EXIT

  # Give the container ~20 seconds to come up
  - |
    attempts=0
    echo -n "Waiting for Nixery to start ..."
    until $(curl --fail --silent "http://localhost:8080/v2/"); do
      [[ attempts -eq 30 ]] && echo "Nixery container failed to start!" && exit 1
      ((attempts++))
      echo -n "."
      sleep 1
    done

  # Pull and run an image of the current CPU architecture
  - |
    case $(uname -m) in
      x86_64)
        docker run --rm localhost:8080/hello hello
        ;;
      aarch64)
        docker run --rm localhost:8080/arm64/hello hello
        ;;
    esac

  # Pull an image of the opposite CPU architecture (but without running it)
  - |
    case $(uname -m) in
    x86_64)
      docker pull localhost:8080/arm64/hello
      ;;
    aarch64)
      docker pull localhost:8080/hello
      ;;
    esac