I’m at the very last part of an assignment and for the life of me I can’t get this to work.
I need to host a website that is deployed by a gitlab cicd pipeline, needs to run tests, build and deploy all automically.
I’m hosting with digitalOcean and all my jobs succeed, in docker ps it shows the containers but when I go to the webaddress it doesn’t want to connect
I’ll give everything, so there will be some unnecessary information, but I’m just lost right now, I’ll be forever thankful if you can help me
(images are public on docker hub listed in the yml file)
Pastebin of build output: https://pastebin.com/fdGbH0e4
Pastebin of deploy output: https://pastebin.com/S2jAjTUY
.gitlab-ci.yml
variables:
IMAGE_NAME_BACKEND: sjorsnl77/pipeline_ipsenh-backend
IMAGE_NAME_FRONTEND: sjorsnl77/pipeline_ipsenh-frontend
IMAGE_TAG: ipsenh-app-1.0
stages:
- verify
- build
- tests
- deploy
services:
- docker:dind
verify_backend:
stage: verify
image: maven:3.9.6-amazoncorretto-17
script:
- cd PintAndPillageJavaBackend
- mvn checkstyle:checkstyle
cache:
key: ${CI_COMMIT_REF_SLUG}-maven
paths:
- .m2/repository/
policy: pull-push
artifacts:
when: always
expire_in: 1 day
paths:
- "PintAndPillageJavaBackend/target/checkstyle-result.xml"
verify_frontend:
stage: verify
image: node:latest
script:
- cd PintAndPillageFrontend
- npm ci
- ./node_modules/.bin/eslint . --output-file eslint-report.txt --quiet || true
cache:
key: ${CI_COMMIT_REF_SLUG}-npm
paths:
- node_modules/
artifacts:
when: always
paths:
- "PintAndPillageFrontend/eslint-report.txt"
expire_in: 1 day
build:
stage: build
image: docker
services:
- docker:dind
variables:
DOCKER_TLS_CERTDIR: "/certs"
before_script:
- docker login -u "$DOCKER_USER" -p "$DOCKER_PASS"
script:
- docker build -t $IMAGE_NAME_BACKEND:$IMAGE_TAG PintAndPillageJavaBackend
- docker build -t $IMAGE_NAME_FRONTEND:$IMAGE_TAG PintAndPillageFrontend
- docker push $IMAGE_NAME_BACKEND:$IMAGE_TAG
- docker push $IMAGE_NAME_FRONTEND:$IMAGE_TAG
cache:
paths:
- .m2/repository/
- node_modules/
test_backend:
stage: tests
image: docker
script:
- docker login -u "$DOCKER_USER" -p "$DOCKER_PASS"
- docker-compose up --build -d db backend
- docker-compose exec backend ./mvnw test
- docker-compose exec backend sh -c "cp -r target/surefire-reports/. /test-output/backend/"
- docker-compose down
artifacts:
when: always
paths:
- test-output/backend/
expire_in: 1 day
test_frontend:
stage: tests
image: docker
script:
- docker login -u "$DOCKER_USER" -p "$DOCKER_PASS"
- docker-compose up --build -d frontend
- docker-compose exec frontend npm run test:unit
- docker-compose exec frontend sh -c "cp -r ./test-output/frontend/. /test-output/frontend/"
- docker-compose down
artifacts:
when: always
paths:
- test-output/frontend/
expire_in: 1 day
deploy_app:
stage: deploy
before_script:
- chmod 400 $SSH_KEY
script:
- ssh -o StrictHostKeyChecking=no -i $SSH_KEY root@$IP_SERVER "
docker login -u $DOCKER_USER -p $DOCKER_PASS;
if [ -n "$(docker ps -aq)" ]; then
docker ps -aq | xargs docker stop | xargs docker rm;
fi;
docker run -d -p 8080:8080 $IMAGE_NAME_BACKEND:$IMAGE_TAG;
docker run -d -p 3000:3000 $IMAGE_NAME_FRONTEND:$IMAGE_TAG;
"
docker-compose.yml
services:
db:
image: postgres:latest
restart: always
environment:
POSTGRES_DB: PintAndPillage
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
- postgres-data:/var/lib/postgresql/data
ports:
- "5432:5432"
backend:
build:
context: ./PintAndPillageJavaBackend
dockerfile: Dockerfile
ports:
- "8080:8080"
depends_on:
- db
environment:
SPRING_PROFILES_ACTIVE: dev
SPRING_DATASOURCE_URL: ${DATASOURCE_URL}
SPRING_DATASOURCE_USERNAME: ${DATASOURCE_USERNAME}
SPRING_DATASOURCE_PASSWORD: ${DATASOURCE_PASSWORD}
SPRING_JPA_HIBERNATE_DIALECT: ${HIBERNATE_DIALECT}
SPRING_JPA_HIBERNATE_DDL_AUTO: ${HIBERNATE_DDL}
SERVER_ERROR_INCLUDE_MESSAGE: always
JWT_SECRET: ${JWT_SECRET}
volumes:
- ./test-output/backend:/test-output/backend
frontend:
build:
context: ./PintAndPillageFrontend
dockerfile: Dockerfile
ports:
- "3000:3000"
depends_on:
- backend
volumes:
- ./test-output/frontend:/test-output/frontend
volumes:
postgres-data:
Dockerfile frontend
FROM node:14
WORKDIR /app
COPY . /app
RUN npm install
CMD ["npm", "run", "serve"]
Dockerfile backend
FROM openjdk:17
WORKDIR /app
COPY . /app
RUN chmod +x mvnw
RUN ./mvnw install
CMD ["./mvnw", "spring-boot:run"]
Even the terminal shows it (weird that the backend is now not showing, but even without the backend it should run the frontend, but you just can’t log in)
188.166.4.5:3000, 188.166.4.5:8080, 188.166.4.5. All don’t work with connecting