-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitlab-ci.yml
More file actions
51 lines (47 loc) · 1.36 KB
/
gitlab-ci.yml
File metadata and controls
51 lines (47 loc) · 1.36 KB
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
stages:
- build
- test
- deploy
variables:
DOCKER_IMAGE: wben1998/cscc01-project
DOCKER_TAG: latest
# Build the Docker images for the backend and frontend
build:
stage: build
image: docker:latest
services:
- docker:dind
script:
# Log in to Docker Hub using API key
- echo "$DOCKER_HUB_API_KEY" | docker login -u "$DOCKER_HUB_USERNAME" --password-stdin
# Build the backend image
- docker build -t $DOCKER_IMAGE-backend:$DOCKER_TAG ./backend
# Build the frontend image
- docker build -t $DOCKER_IMAGE-frontend:$DOCKER_TAG ./frontend
# Push the backend image to Docker Hub
- docker push $DOCKER_IMAGE-backend:$DOCKER_TAG
# Push the frontend image to Docker Hub
- docker push $DOCKER_IMAGE-frontend:$DOCKER_TAG
# Test the backend and frontend
test:
stage: test
image: docker:latest
services:
- docker:dind
script:
# Run backend tests
- docker run --rm $DOCKER_IMAGE-backend:$DOCKER_TAG npm test
# Run frontend tests
- docker run --rm $DOCKER_IMAGE-frontend:$DOCKER_TAG npm test
allow_failure: true
# Deploy the project (optional)
deploy:
stage: deploy
image: docker:latest
services:
- docker:dind
script:
# Run the backend
- docker run -d -p 3000:3000 $DOCKER_IMAGE-backend:$DOCKER_TAG
# Run the frontend
- docker run -d -p 8081:8081 $DOCKER_IMAGE-frontend:$DOCKER_TAG