.gitlab-ci.yml 1.6 KB
Newer Older
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
image: docker:stable

services:
  - docker:dind

variables:
    BACKEND_DIR: api
    FRONTEND_DIR: client
    NODE_IMAGE: node:14.8.0
    IMAGE_TAG_LATEST_FRONTEND: mimir-client:latest
    IMAGE_TAG_LATEST_BACKEND: mimir-api:latest
  
stages:
  - deploy

# Cache node modules in between builds
cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    # backend dependencies
    - $BACKEND_DIR/node_modules
    # frontend dependencies
    - $FRONTEND_DIR/node_modules

###################################################################################################
# Deploy stage jobs

deploy backend:
  stage: deploy
  script:
    - docker info
    - docker build
      -t $IMAGE_TAG_LATEST_BACKEND
      -f $BACKEND_DIR/Dockerfile
      ./$BACKEND_DIR
    - docker image ls
    - echo "$REGISTRY_PASSWORD" | docker login $REGISTRY_USER --username $CI_REGISTRY_USER --password-stdin
    - docker tag $IMAGE_TAG_LATEST_BACKEND $REGISTRY_USER/$IMAGE_TAG_LATEST_BACKEND
    - docker push $REGISTRY_USER/$IMAGE_TAG_LATEST_BACKEND

  only:
    changes:
      - api/**
      - api/**/*
    refs:
      - master

deploy frontend:
  stage: deploy
  script:
    - docker info
    - docker build
      -t $IMAGE_TAG_LATEST_FRONTEND
      -f $FRONTEND_DIR/Dockerfile
      ./$FRONTEND_DIR
    - docker image ls
    - echo "$REGISTRY_PASSWORD" | docker login $REGISTRY_USER --username $CI_REGISTRY_USER --password-stdin
    - docker tag $IMAGE_TAG_LATEST_FRONTEND $REGISTRY_USER/$IMAGE_TAG_LATEST_FRONTEND
    - docker push $REGISTRY_USER/$IMAGE_TAG_LATEST_FRONTEND
  only:
    changes:
      - client/**
      - client/**/*
    refs:
      - master