Skip to content
Snippets Groups Projects
.gitlab-ci.yml 4.15 KiB
Newer Older
Lemni's avatar
Lemni committed
stages:
  - build
  - deploy

Lemni's avatar
Lemni committed
.prepare_pipenv: &prepare_pipenv  |
  export LC_ALL=C.UTF-8
  export LANG=C.UTF-8
  pip install pipenv --ignore-installed
  set +e
  pipenv --venv; NO_VENV=$? ; echo 'No fail'
  set -e
  if [ $NO_VENV -eq 1 ]; then
Lemni's avatar
Lemni committed
    pipenv --python 3.11
Lemni's avatar
Lemni committed
  fi
Lemni's avatar
Lemni committed
  #pipenv run pip install pip=="23.1"
Lemni's avatar
Lemni committed
  pipenv install --dev

.prepare_awscli: &prepare_awscli  |
  export LC_ALL=C.UTF-8
  export LANG=C.UTF-8
  pip install pipenv --ignore-installed
  set +e
  pipenv --venv; NO_VENV=$? ; echo 'No fail'
  set -e
  if [ $NO_VENV -eq 1 ]; then
Lemni's avatar
Lemni committed
    pipenv --python 3.11
Lemni's avatar
Lemni committed
  fi
  pipenv run pip install awscli

.get_ecscli: &get_ecscli |
  if [ -e ecs-cli ]
  then
    echo "ecs-cli already downloaded"
  else
    apk add curl
    curl -o ./ecs-cli https://amazon-ecs-cli.s3.amazonaws.com/ecs-cli-linux-amd64-latest
  fi
  chmod +x ecs-cli


variables:
   GIT_SUBMODULE_STRATEGY: recursive
   DOCKER_TLS_CERTDIR: ""


build_image_prod:
  stage: build
  image: docker
  services:
    - docker:dind
  before_script:
    - apk --no-cache add --virtual git build-base gcc libgcc musl-dev jpeg-dev zlib-dev libc-dev libffi-dev mariadb-dev openssl-dev python3-dev py3-pip
    - *prepare_awscli
  script:
    - $(pipenv run aws ecr get-login --no-include-email --region eu-west-1 )
    - |
      set +e
Lemni's avatar
Lemni committed
      docker pull "${AWS_REGISTRY_IMAGE}:$CI_COMMIT_REF_NAME"
Lemni's avatar
Lemni committed
      set -e
Lemni's avatar
Lemni committed
    - docker build --cache-from "${AWS_REGISTRY_IMAGE}:$CI_COMMIT_REF_NAME" -t "${AWS_REGISTRY_IMAGE}:$CI_COMMIT_REF_NAME" .
    - docker push "$AWS_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME"
Lemni's avatar
Lemni committed
  only:
    - tags
  cache:
    key: docker
    paths:
      - .venv
      - .pip-cache
      - Pipfile.lock


deploy_prod:
  stage: deploy
Lemni's avatar
Lemni committed
  image: python:3.11-alpine
Lemni's avatar
Lemni committed
  environment: production
  before_script:
    - *get_ecscli
  only:
    - tags
  script:
Lemni's avatar
Lemni committed
    - export TAG=$CI_COMMIT_REF_NAME
Lemni's avatar
Lemni committed
    - source backend/production.env
    - ./ecs-cli configure --region eu-west-1 --cluster spotfleet-gitlab
    - ./ecs-cli compose --file ecs-compose.yml  --ecs-params ecs-params.yml --project-name saf-prod service up --create-log-groups --target-group-arn $AWS_TG_ARN --container-name saf --container-port 80 --timeout 10 --role $AWS_ROLE
  cache:
    key: python
    paths:
      - .venv
      - .pip-cache
      - Pipfile.lock
      - ecs-cli


build_image_staging:
  stage: build
  image: docker
  services:
    - docker:dind
  before_script:
    - apk --no-cache add --virtual git build-base gcc libgcc musl-dev jpeg-dev zlib-dev libc-dev libffi-dev mariadb-dev openssl-dev python3-dev py3-pip
    - *prepare_awscli
  script:
    - $(pipenv run aws ecr get-login --no-include-email --region eu-west-1 )
    - |
      set +e
Lemni's avatar
Lemni committed
      docker pull "${AWS_REGISTRY_IMAGE}:PREPROD-$CI_COMMIT_REF_NAME"
Lemni's avatar
Lemni committed
      set -e
Lemni's avatar
Lemni committed
    - docker build --cache-from "${AWS_REGISTRY_IMAGE}:PREPROD-$CI_COMMIT_REF_NAME" -t "${AWS_REGISTRY_IMAGE}:PREPROD-$CI_COMMIT_REF_NAME" .
    - docker push "$AWS_REGISTRY_IMAGE:PREPROD-$CI_COMMIT_REF_NAME"
Lemni's avatar
Lemni committed
  except:
    - tags
  cache:
    key: docker
    paths:
      - .venv
      - .pip-cache
      - Pipfile.lock 


deploy_staging:
    stage: deploy
Lemni's avatar
Lemni committed
    image: python:3.11-alpine
Lemni's avatar
Lemni committed
    environment: staging
    before_script:
      - *get_ecscli
    except:
      - tags
    script:
Lemni's avatar
Lemni committed
      - export TAG=PREPROD-$CI_COMMIT_REF_NAME
Lemni's avatar
Lemni committed
      - source backend/staging.env
      - ./ecs-cli configure --region eu-west-1 --cluster spotfleet-gitlab
      - ./ecs-cli compose --file ecs-compose.yml  --ecs-params ecs-params.yml --project-name saf-stag service up --create-log-groups --target-group-arn $AWS_TG_ARN --container-name saf --container-port 80 --timeout 10 --role $AWS_ROLE
    cache:
      key: python
      paths:
        - .venv
        - .pip-cache
        - Pipfile.lock
        - ecs-cli


build_prod_front:
    stage: build
    when: manual
    image: node:latest
    script:
      - cd frontend/SAF_vue
      - npm install -g @vue/cli@latest
      - npm install
      - npm run build
      - mv dist ../..
    artifacts:
      paths:
        - dist/
      expire_in: 1 hour


deploy_prod_front:
    stage: deploy
    needs: 
      - job: build_prod_front
    image: python:latest
    script:
      - pip install awscli
      - aws s3 sync ./dist s3://lem-usb-front