CD frontend

This commit is contained in:
FyloZ 2021-02-11 22:27:36 -05:00
parent 41b2659a6d
commit aae85bef31
3 changed files with 60 additions and 17 deletions

View File

@ -28,22 +28,6 @@ build-frontend:
- docker build --cache-from $CI_REGISTRY_IMAGE_NG -f ng.Dockerfile -t $CI_REGISTRY_IMAGE_NG --build-arg JDK_VERSION=$JDK_VERSION --build-arg GRADLE_VERSION=$GRADLE_VERSION .
- docker push $CI_REGISTRY_IMAGE_NG
compile-kotlin-backend:
stage: test
needs: ['build-backend']
variables:
COMPILE_KOTLIN_CONTAINER_NAME: "cre_backend_gradle_compile_kotlin"
script:
- docker run --name $COMPILE_KOTLIN_CONTAINER_NAME --rm $CI_REGISTRY_IMAGE_GRADLE gradle compileKotlin
compile-java-backend:
stage: test
needs: ['build-backend']
variables:
COMPILE_JAVA_CONTAINER_NAME: "cre_backend_gradle_compile_java"
script:
- docker run --name $COMPILE_JAVA_CONTAINER_NAME --rm $CI_REGISTRY_IMAGE_JAVA gradle compileJava
test-backend:
stage: test
needs: ['build-backend']
@ -86,6 +70,8 @@ package-frontend:
- docker run --name $PACKAGE_CONTAINER_NAME $CI_REGISTRY_IMAGE_NG gradle buildFrontend
- docker cp $PACKAGE_CONTAINER_NAME:/usr/src/cre/dist/frontend/ dist/
- zip -r $ARTIFACT_NAME.zip dist/
- docker build -t $CI_REGISTRY_IMAGE_FRONTEND -f frontend.Dockerfile --build-arg PORT=$FRONTEND_PORT --build-arg ARTIFACT_NAME=$ARTIFACT_NAME .
- docker push $CI_REGISTRY_IMAGE_FRONTEND
after_script:
- docker stop $PACKAGE_CONTAINER_NAME || true
- docker rm $PACKAGE_CONTAINER_NAME || true
@ -105,6 +91,7 @@ package-frontend:
- ssh-add ~/.ssh/id_rsa
- ssh-keyscan -p $DEPLOYMENT_SERVER_SSH_PORT -H $DEPLOYMENT_SERVER >> ~/.ssh/known_hosts
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- ssh -p $DEPLOYMENT_SERVER_SSH_PORT $DEPLOYMENT_SERVER_USERNAME@$DEPLOYMENT_SERVER "docker stop $DEPLOYED_CONTAINER_NAME || true && docker rm $DEPLOYED_CONTAINER_NAME || true"
deploy-backend:
stage: deploy
@ -114,6 +101,16 @@ deploy-backend:
DEPLOYED_CONTAINER_NAME: "cre_backend"
<<: *before_deploy
script:
- ssh -p $DEPLOYMENT_SERVER_SSH_PORT $DEPLOYMENT_SERVER_USERNAME@$DEPLOYMENT_SERVER "docker stop $DEPLOYED_CONTAINER_NAME || true && docker rm $DEPLOYED_CONTAINER_NAME || true"
- ssh -p $DEPLOYMENT_SERVER_SSH_PORT $DEPLOYMENT_SERVER_USERNAME@$DEPLOYMENT_SERVER "docker login -u $CI_USERNAME -p $CI_ACCESS_TOKEN $CI_REGISTRY && docker pull $CI_REGISTRY_IMAGE_BACKEND"
- ssh -p $DEPLOYMENT_SERVER_SSH_PORT $DEPLOYMENT_SERVER_USERNAME@$DEPLOYMENT_SERVER "docker run -d -p $BACKEND_PORT:$BACKEND_PORT --name=$DEPLOYED_CONTAINER_NAME -e spring_profiles_active=$BACKEND_PROFILES -e spring_datasource_username=$DB_USERNAME -e spring_datasource_password=$DB_PASSWORD -e spring_datasource_url=$DB_URL $CI_REGISTRY_IMAGE_BACKEND"
deploy-frontend:
stage: deploy
image: alpine:latest
needs: ['package-frontend']
variables:
DEPLOYED_CONTAINER_NAME: "cre_frontend"
<<: *before_deploy
script:
- ssh -p $DEPLOYMENT_SERVER_SSH_PORT $DEPLOYMENT_SERVER_USERNAME@$DEPLOYMENT_SERVER "docker login -u $CI_USERNAME -p $CI_ACCESS_TOKEN $CI_REGISTRY && docker pull $CI_REGISTRY_IMAGE_FRONTEND"
- ssh -p $DEPLOYMENT_SERVER_SSH_PORT $DEPLOYMENT_SERVER_USERNAME@$DEPLOYMENT_SERVER "docker run -d -p $FRONTEND_PORT:$FRONTEND_PORT --name=$DEPLOYED_CONTAINER_NAME $CI_REGISTRY_IMAGE_FRONTEND"

18
frontend.Dockerfile Normal file
View File

@ -0,0 +1,18 @@
FROM nginx:mainline-alpine
WORKDIR /usr/bin/cre/
ARG ARTIFACT_NAME=ColorRecipesExplorer-ng
COPY $ARTIFACT_NAME.zip .
COPY frontend.nginx.conf /etc/nginx/nginx.conf
RUN apk update
RUN apk add --no-cache zip
RUN unzip $ARTIFACT_NAME.zip
RUN rm $ARTIFACT_NAME.zip
ARG PORT=4200
EXPOSE $PORT
CMD ["nginx", "-g", "daemon off;"]

28
frontend.nginx.conf Normal file
View File

@ -0,0 +1,28 @@
events {
worker_connections 1024;
}
http {
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
server {
include /etc/nginx/mime.types;
listen 80;
root /usr/bin/cre/;
index index.html;
location / {
try_files $uri$args $uri$args/ /index.html;
}
}
}