diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..140888e --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,105 @@ +variables: + DOCKER_REGION: "registry.cn-qingdao.aliyuncs.com" + DOCKER_NAMESPACE: "lacus" + DOCKER_USERNAME: "rainsun20170129" + DOCKER_PASSWORD: "100200300Wdy*" + APP_NAME: "canary_fe" + IMAGE_NAME: "$DOCKER_REGION/$DOCKER_NAMESPACE/$APP_NAME:$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA" + DOCKER_FILE_PATH: "./Dockerfile" + +stages: + - build + - test + - clear + - deploy + - clear_test + +build: + stage: build + image: docker:latest + services: + - name: docker:dind + tags: + - dockerbase + script: + - ls -a + - docker login --username=${DOCKER_USERNAME} --password=${DOCKER_PASSWORD} ${DOCKER_REGION} + - docker build -t ${IMAGE_NAME} -f ${DOCKER_FILE_PATH} . + - docker push ${IMAGE_NAME} + - docker rmi ${IMAGE_NAME} + +test: + stage: test + tags: + - dockerbase + script: + - ls -a + - docker login --username=${DOCKER_USERNAME} --password=${DOCKER_PASSWORD} ${DOCKER_REGION} + - docker pull ${IMAGE_NAME} + - docker run -d --name ${APP_NAME} -p 8080:80 ${IMAGE_NAME} + cache: + policy: pull + +clear_master: + stage: clear + tags: + - ali2 + only: + - master + script: + - docker stop pan_${APP_NAME} + - docker rm pan_${APP_NAME} + allow_failure: true + when: manual + +deploy_master: + stage: deploy + tags: + - ali2 + only: + - master + script: + - ls -a + - docker login --username=${DOCKER_USERNAME} --password=${DOCKER_PASSWORD} ${DOCKER_REGION} + - docker pull ${IMAGE_NAME} + - docker run -d --name pan_${APP_NAME} -p 127.0.0.1:5005:80 ${IMAGE_NAME} + cache: + policy: pull + when: manual + +clear_outside: + stage: clear + tags: + - ali2 + only: + - outside + script: + - docker stop ${APP_NAME} + - docker rm ${APP_NAME} + allow_failure: true + when: manual + +deploy_outside: + stage: deploy + tags: + - ali2 + only: + - outside + script: + - ls -a + - docker login --username=${DOCKER_USERNAME} --password=${DOCKER_PASSWORD} ${DOCKER_REGION} + - docker pull ${IMAGE_NAME} + - docker run -d --name ${APP_NAME} -p 127.0.0.1:5004:80 ${IMAGE_NAME} + cache: + policy: pull + when: manual + +clear_test: + stage: clear_test + tags: + - dockerbase + script: + - docker stop ${APP_NAME} + - docker rm ${APP_NAME} + allow_failure: true + when: manual \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 76819a8..1d62cc9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ -FROM nginx -COPY dist/ /usr/share/nginx/html/ +FROM nginx:1.18.0 + +COPY dist/ /usr/share/nginx/html COPY nginx/default.conf /etc/nginx/conf.d/default.conf \ No newline at end of file diff --git a/nginx/default.conf b/nginx/default.conf index 790cda0..1da89be 100644 --- a/nginx/default.conf +++ b/nginx/default.conf @@ -1,17 +1,24 @@ server { - listen 80; - server_name localhost; + listen 80; + listen [::]:80; + server_name localhost; - access_log /var/log/nginx/host.access.log main; - error_log /var/log/nginx/error.log error; + access_log /var/log/nginx/host.access.log main; + error_log /var/log/nginx/error.log error; - location / { - root /usr/share/nginx/html; - index index.html index.htm; - try_files $uri $uri/ /index.html; - } - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root /usr/share/nginx/html; - } -} \ No newline at end of file + location / { + root /usr/share/nginx/html; + index index.html index.htm; + try_files $uri $uri/ /index.html; + } + + error_page 404 /404.html; + location = /404.html { + root /usr/share/nginx/html; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +}