Commit 1dfdd018 authored by Mark Harding's avatar Mark Harding
Browse files

(feat): staging flow for frontend too

-subdomain=sgtpepper
parent 78c51325
Loading
Loading
Loading
Loading
+88 −4
Original line number Original line Diff line number Diff line
@@ -6,6 +6,7 @@ services:
stages:
stages:
  - test
  - test
  - build
  - build
  - prepare
  - deploy
  - deploy


test:
test:
@@ -14,8 +15,32 @@ test:
  script:
  script:
    - npm install # Should be cached...
    - npm install # Should be cached...
    - npm run test -- --no-watch --no-progress --browsers=ChromeHeadlessCI
    - npm run test -- --no-watch --no-progress --browsers=ChromeHeadlessCI
  except:
    refs:
      - master
      - test/gitlab-ci-docker-images

build:staging:
  stage: build
  script:
    - npm install # TODO: Why is this needed?
    - npm run postinstall
    - npm install -g gulp-cli
    - gulp build.sass && gulp build.sass ##weird build needs to be run twice for now
    - sh build/base-locale.sh dist
  cache:
    paths:
      - dist
    policy: push
  only:
    variables:
      - $CI_COMMIT_MESSAGE =~ /-subdomain/
  except:
    refs:
      - master
      - test/gitlab-ci-docker-images


build:
build:production:en:
  stage: build
  stage: build
  script:
  script:
    - npm install # TODO: Why is this needed?
    - npm install # TODO: Why is this needed?
@@ -33,11 +58,70 @@ build:
      - master
      - master
      - test/gitlab-ci
      - test/gitlab-ci


deploy:
build:production:i18n:
  stage: build
  script:
    - npm install # TODO: Why is this needed?
    - npm run postinstall
    - npm install -g gulp-cli
    - gulp build.sass --deploy-url=https://cdn-assets.minds.com/front/dist/en && gulp build.sass --deploy-url=https://cdn-assets.minds.com/front/dist/en ##weird build needs to be run twice for now
    - sh build/i18n-locales-all.sh dist https://cdn-assets.minds.com/front/dist
  cache:
    paths:
      - dist
    policy: push
  only:
    refs:
      - master
      - test/gitlab-ci

prepare:
  stage: prepare
  image: minds/ci:latest
  script:
    - docker login -u gitlab-ci-token -p ${CI_BUILD_TOKEN} ${CI_REGISTRY} 
    - docker build -t $CI_REGISTRY_IMAGE/front-init:$CI_BUILD_REF -f containers/front-init/Dockerfile dist/.
    - docker push $CI_REGISTRY_IMAGE/front-init:$CI_BUILD_REF
  cache:
    paths:
      - dist
    policy: pull
  environment:
    name: staging
  except:
    refs:
      - master

deploy:staging:
  stage: deploy
  image: minds/helm-eks:latest
  script:
    - aws eks update-kubeconfig --name=sandbox
    - STAGING_SUBDOMAIN=$(echo $CI_COMMIT_MESSAGE | sed -n 's/.* -subdomain=\([^ ]*\).*/\1/p')
    - echo "Subdomain will be setup at $STAGING_SUBDOMAIN"
    - git clone --branch=sandbox-wip https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/minds/helm-charts.git
    - "helm upgrade \
        --install \
        --reuse-values \
        --set frontInit.image.repository=$CI_REGISTRY_IMAGE/front-init \
	      --set frontInit.image.tag=$CI_BUILD_REF \
        --set domain=$STAGING_SUBDOMAIN.$STAGING_DOMAIN \
        --wait \
        $STAGING_SUBDOMAIN \
        ./helm-charts/minds"
  environment:
    name: staging
  only:
    variables:
      - $CI_COMMIT_MESSAGE =~ /-subdomain/
  except: 
    refs:
      - master

deploy:production:
  stage: deploy
  stage: deploy
  image: minds/ci:latest
  script:
  script:
    - apk add --no-cache python py-pip
    - pip install awscli
    - aws s3 sync dist $REPOSITORY_URL
    - aws s3 sync dist $REPOSITORY_URL
    - aws ecs update-service --service=$SERVICE --force-new-deployment --region us-east-1 --cluster=$CLUSTER
    - aws ecs update-service --service=$SERVICE --force-new-deployment --region us-east-1 --cluster=$CLUSTER
  cache:
  cache:
+3 −0
Original line number Original line Diff line number Diff line
FROM alpine:edge

COPY . dist
 No newline at end of file