-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
105 lines (100 loc) · 3.47 KB
/
.gitlab-ci.yml
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
stages:
- test
- build
- deploy
# Run flake8 to check for code quality
lint-test-job:
image: python:3-bullseye
stage: test
script:
- pip install flake8
- flake8 api
services:
- docker:dind
build-fastapi-service-image:
stage: build
image: docker:git
variables:
GITLAB_IMAGE: ${CI_REGISTRY_IMAGE}/api_image
before_script:
# $CI_JOB_TOKEN is variable automatically added by Gitlab: see https://docs.gitlab.com/ee/ci/variables/predefined_variables.html#variables-reference
- echo $CI_JOB_TOKEN | docker login -u gitlab-ci-token registry.gitlab.com --password-stdin
script:
- docker build --tag $GITLAB_IMAGE:latest api
- docker push $GITLAB_IMAGE:latest
only:
- main
# Run the unit tests
api-unit-tests-job:
image: python:3-bullseye
stage: test
needs:
- lint-test-job
script:
- cd api
- pip install -r requirements.txt
- python -m pytest
variables:
DATABASE_URL: postgresql://wagegauge:secret@db/wagegauge-data
WAIT_HOSTS: db:5432
SIGNING_KEY: 7091da32cfdd6b4eb2991d9b9885860bdedc1de05d972b416791b941ad25a721
# # Build the React/JavaScript front-end
build-front-end-job:
stage: build
image: node:lts-bullseye
needs:
- lint-test-job
variables:
# If either of these variables is defined in the GitLab
# CI/CD variables, that value will override the value here.
# You need to substitute in your real values for
# GROUP_NAME, PROJECT_NAME, & WEBSERVICE_NAME below.
PUBLIC_URL: https://wagegauge.gitlab.io/WageGauge/
REACT_APP_API_HOST: https://feb-23-pt-3-wagegauge2-api.mod3projects.com
script:
- cd ghi
- npm install
- npm run build
- cp build/index.html build/404.html
artifacts:
paths:
- ghi/build/
# # Deploy the React/JavaScript front-end to GitLab pages
pages:
stage: deploy
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
dependencies:
- build-front-end-job
needs:
- build-front-end-job
script:
- mv ghi/build/ public
artifacts:
paths:
- public
# # Build Sample Service:
# build-back-end-job:
# image: docker:20-dind
# stage: build
# services:
# - docker:20-dind
# before_script:
# - export DOCKER_REGISTRY_USER=$CI_REGISTRY_USER # built-in GitLab Registry User
# - export DOCKER_REGISTRY_PASSWORD=$CI_REGISTRY_PASSWORD # built-in GitLab Registry Password
# - export DOCKER_REGISTRY_URL=$CI_REGISTRY # built-in GitLab Registry URL
# - export COMMIT_HASH=$CI_COMMIT_SHA # Your current commit sha
# - export IMAGE_NAME_WITH_REGISTRY_PREFIX=$CI_REGISTRY_IMAGE # Your repository prefixed with GitLab Registry URL
# - docker login -u "$DOCKER_REGISTRY_USER" -p "$DOCKER_REGISTRY_PASSWORD" $DOCKER_REGISTRY_URL # Instructs GitLab to login to its registry
# script:
# - cd sample_service
# - echo "Building... " # MAKE SURE NO SPACE ON EITHER SIDE OF = IN THE FOLLOWING LINE
# - export CONTAINER_FULL_IMAGE_NAME_WITH_TAG=$IMAGE_NAME_WITH_REGISTRY_PREFIX/sample_service_image:$COMMIT_HASH
# - docker build -f ./Dockerfile --pull -t built-sample_service .
# - docker tag built-sample_service "$CONTAINER_FULL_IMAGE_NAME_WITH_TAG"
# - docker push "$CONTAINER_FULL_IMAGE_NAME_WITH_TAG"
# - echo $CONTAINER_FULL_IMAGE_NAME_WITH_TAG
# - echo "Deploying on CapRover..."
# - docker run caprover/cli-caprover caprover deploy --caproverUrl $CAPROVER_URL --caproverPassword $CAPROVER_PASSWORD --caproverApp $CAPROVER_APP --imageName $CONTAINER_FULL_IMAGE_NAME_WITH_TAG
# only:
# - main