.gitlab-ci.yml 1.9 KB
Newer Older
Dario Pinto's avatar
Dario Pinto committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
stages:
  - build
  - image
  - deploy

# Define some conditions to run the whole pipeline
workflow:
  rules:
    - if: $CI_MERGE_REQUEST_ID                     # Run on MRs
    - if: $CI_COMMIT_TAG                           # Run on tags
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH  # Run on master

# Customize the build rules and the artifacts here. You probably want to adjust
# "opam.locked"
# We define a cache in order to keep the switch with the dependencies installed,
# unless the opam.locked file has changed.
build:
  stage: build
  image: registry.ocamlpro.com/ocamlpro/ocaml-docker-images:4.12
  before_script:
Louis Gesbert's avatar
Louis Gesbert committed
21
    - sudo apk add openssl-libs-static
zapashcanon's avatar
zapashcanon committed
22
    - opam switch create . ocaml-system --deps-only --locked
Dario Pinto's avatar
Dario Pinto committed
23 24
    - opam clean --switch-cleanup
  script:
Louis Gesbert's avatar
Louis Gesbert committed
25
    - OCAMLPARAM="_,cclib=-static-pie,cclib=-static" opam exec -- dune build --profile release @all
Dario Pinto's avatar
Dario Pinto committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
    - opam exec -- dune runtest
    - mv _build/default/src/server.exe .
  artifacts:
    paths:
      - server.exe

include:
  - project: 'OCamlPro/gitlab-deployments'
    ref: master
    file: deploy.yml

# Builds and pushes the Docker image using Kaniko
make-image:
  extends: .make-image  # defined in deploy.yml
  variables:
    DOCKERFILE: /kaniko/Dockerfile
    # don't need a local 'git clone'
    GIT_STRATEGY: "none"
  before_script:
    # Write the Dockerfile for the image we want to generate
    # Here we inherit from nginx and just add the contents of our web-app
    - |
      echo "\
49 50
      FROM bitnami/nginx:latest
      ADD server.exe /opt/bitnami/nginx/sbin/nginx
Dario Pinto's avatar
Dario Pinto committed
51 52 53 54 55 56 57 58 59 60 61
      " > $DOCKERFILE

# Deployments are pre-defined in the "dev" environment; they will be stopped
# after 3 days unless they are on the default branch (master).

# To define production deployments, ensure the domain name is correct, and set
# the corresponding DNS record as "CNAME" to "a.ocaml.pro"
deploy-prod:
  extends: .deploy-prod
  variables:
    PUBLIC_HOST: www.ocamlpro.com