diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5ee7e30 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +*/.git/* \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..78acac1 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,49 @@ +image: docker:latest + +stages: + - Build Base + - Push Images + +0-build-base: + stage: Build Base + artifacts: + expire_in: 1 week + paths: + - ./images/ + tags: + - docker + before_script: + - mkdir ./images + script: + - docker build --pull -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" . + - docker save --output "./images/$CI_COMMIT_SHORT_SHA.tar" "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" + +1A-push-version: + stage: Push Images + dependencies: + - 0-build-base + tags: + - docker + when: manual + before_script: + - docker load --input "./images/$CI_COMMIT_SHORT_SHA.tar" + - docker load --input "./images/$CI_COMMIT_SHORT_SHA-git.tar" + - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin + script: + - docker tag "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" "$CI_REGISTRY_IMAGE:$CI_JOB_ID" + - docker push "$CI_REGISTRY_IMAGE:$CI_JOB_ID" + +1B-push-latest: + stage: Push Images + dependencies: + - 0-build-base + tags: + - docker + when: manual + before_script: + - docker load --input "./images/$CI_COMMIT_SHORT_SHA.tar" + - docker load --input "./images/$CI_COMMIT_SHORT_SHA-git.tar" + - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin + script: + - docker tag "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" "$CI_REGISTRY_IMAGE:latest" + - docker push "$CI_REGISTRY_IMAGE:latest" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e518bf7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM nginx:1.16 +USER root +WORKDIR /var/www + +# MySQL 5.7 (Homefully not version 8...) +RUN apt-get update && apt-get install mysql-server -y + +# Configure NGINX +ADD https://raw.githubusercontent.com/getgrav/grav/c381bc83040e00c9a8ebe91ac3bda5fe0c217197/webserver-configs/nginx.conf /etc/nginx/conf.d/default.conf +RUN sed -i 's/root \/home\/USER\/www\/html/root \/var\/www/g' /etc/nginx/conf.d/default.conf \ + && sed -i 's/fastcgi_pass unix:\/var\/run\/php\/php7.2-fpm.sock;/fastcgi_pass unix:\/var\/run\/php-fpm.sock;/g' /etc/nginx/conf.d/default.conf \ + && sed -i 's/#listen 80;/listen 80;/g' /etc/nginx/conf.d/default.conf \ + && sed -i '23cuser = nginx' /etc/php7/php-fpm.d/www.conf \ + && sed -i '24cgroup = nginx' /etc/php7/php-fpm.d/www.conf \ + && sed -i '47clisten.owner = nginx' /etc/php7/php-fpm.d/www.conf \ + && sed -i '48clisten.group = nginx' /etc/php7/php-fpm.d/www.conf \ + && sed -i '49clisten.mode = 0660' /etc/php7/php-fpm.d/www.conf \ + && sed -i 's/listen = 127.0.0.1:9000/listen = \/var\/run\/php-fpm.sock/g' /etc/php7/php-fpm.d/www.conf + +COPY /entrypoint.sh / + +# Expose Insecure Web, MySQL Server +EXPOSE 80 3306 +CMD ["/bin/sh", "/entrypoint.sh"] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..abeb0b6 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +echo "[ INFO ] Recursively setting default nginx:nginx permissions on web directory" +chown -R nginx:nginx /var/www + +echo "[ INFO ] Starting PHP-FPM" +php-fpm7 -D # Background + +echo "[ INFO ] Starting cron" +crond # Background + +echo "[ INFO ] Starting nginx" +nginx -g "daemon off;" # Foreground