From 829120fbadd1e271716910cb9ab71c7ddc5f7638 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 10 Feb 2023 23:19:23 +1100 Subject: [PATCH] Update docker container configuration and image --- .gitlab-ci.yml | 12 +++++------ .gitlab-docker-x86_64.yml | 42 +++++++++++++++++---------------------- .gitlab-test.yml | 42 +++++++++++++++++++-------------------- Dockerfile | 18 ++++++++--------- 4 files changed, 54 insertions(+), 60 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b4631f2..34d272e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,14 +1,14 @@ stages: - - test - - build +- test +- build # This folder is cached between builds # http://docs.gitlab.com/ce/ci/yaml/README.html#cache cache: - key: ${CI_COMMIT_REF_SLUG} + key: ${CI_JOB_NAME_SLUG}-${CI_COMMIT_REF_SLUG} paths: - - vendor/ + - vendor/ include: - - .gitlab-test.yml - - .gitlab-docker-x86_64.yml +- .gitlab-test.yml +- .gitlab-docker-x86_64.yml diff --git a/.gitlab-docker-x86_64.yml b/.gitlab-docker-x86_64.yml index 55bc345..c33b8db 100644 --- a/.gitlab-docker-x86_64.yml +++ b/.gitlab-docker-x86_64.yml @@ -1,33 +1,27 @@ docker: - image: docker:latest + variables: + VERSION: latest + DOCKER_HOST: tcp://docker:2375 stage: build + image: docker:latest services: - - docker:dind - - variables: - VERSION: latest - CACHETAG: build-${VERSION} - DOCKER_HOST: tcp://docker:2375 - - tags: - - docker - - x86_64 - only: - - master + - docker:dind before_script: - - docker info - - docker version - - echo "$CI_JOB_TOKEN" | docker login -u "$CI_REGISTRY_USER" "$CI_REGISTRY" --password-stdin - - if [ -n "$GITHUB_TOKEN" ]; then cat $GITHUB_TOKEN |base64 -d > auth.json; fi + - docker info && docker version + - echo "$CI_JOB_TOKEN" | docker login -u "$CI_REGISTRY_USER" "$CI_REGISTRY" --password-stdin + - if [ -n "$GITHUB_TOKEN" ]; then cat $GITHUB_TOKEN |base64 -d > auth.json; fi script: - - if [ -f init ]; then chmod 500 init; fi - - ([ -z "$REFRESH" ] && docker pull ${CI_REGISTRY_IMAGE}:${CACHETAG}) || echo "true" - - echo -n ${CI_COMMIT_SHORT_SHA} > VERSION - - rm -rf vendor/ database/schema database/seeders database/factories - - docker build --cache-from ${CI_REGISTRY_IMAGE}:${CACHETAG} -t ${CI_REGISTRY_IMAGE}:${VERSION} -t ${CI_REGISTRY_IMAGE}:${CACHETAG} . - - docker push ${CI_REGISTRY_IMAGE}:${VERSION} - - docker push ${CI_REGISTRY_IMAGE}:${CACHETAG} + - if [ -f init ]; then chmod 500 init; fi + - echo -n ${CI_COMMIT_SHORT_SHA} > VERSION + - rm -rf vendor/ database/schema database/seeders database/factories/* + - docker build -t ${CI_REGISTRY_IMAGE}:${VERSION} . + - docker push ${CI_REGISTRY_IMAGE}:${VERSION} + tags: + - docker + - x86_64 + only: + - master diff --git a/.gitlab-test.yml b/.gitlab-test.yml index cc42f63..9d93d22 100644 --- a/.gitlab-test.yml +++ b/.gitlab-test.yml @@ -1,42 +1,42 @@ test: - image: ${CI_REGISTRY}/leenooks/php:8.1-fpm-server-test + image: ${CI_REGISTRY}/leenooks/php:8.1-fpm-alpine-pgsql-server-test stage: test # NOTE: This service is dependant on project file configuration, which is not there if the cache was deleted # resulting in the testing to fail on the first run. services: - - name: postgres:15-alpine - alias: postgres-test + - name: postgres:15-alpine + alias: postgres-test variables: POSTGRES_USER: test POSTGRES_PASSWORD: test tags: - - php + - php only: - - master + - master before_script: - - mv .env.testing .env + - mv .env.testing .env - # Install Composer and project dependencies. - - mkdir -p /root/.composer - - if [ -n "$GITHUB_TOKEN" ]; then cat $GITHUB_TOKEN |base64 -d > /root/.composer/auth.json ; fi - - composer install + # Install Composer and project dependencies. + - mkdir -p ${COMPOSER_HOME} + - if [ -n "$GITHUB_TOKEN" ]; then cat $GITHUB_TOKEN |base64 -d > ${COMPOSER_HOME}/auth.json; fi + - composer install - # Generate an application key. Re-cache. - - php artisan key:generate - - php artisan migrate - - php artisan db:seed + # Generate an application key. Re-cache. + - php artisan key:generate + - php artisan migrate + - php artisan db:seed script: - # run laravel tests - - XDEBUG_MODE=coverage php vendor/bin/phpunit --coverage-text --colors=never + # run laravel tests + - XDEBUG_MODE=coverage php vendor/bin/phpunit --coverage-text --colors=never - # run frontend tests - # if you have any task for testing frontend - # set it in your package.json script - # comment this out if you don't have a frontend test - # npm test + # run frontend tests + # if you have any task for testing frontend + # set it in your package.json script + # comment this out if you don't have a frontend test + # npm test diff --git a/Dockerfile b/Dockerfile index 92a94f0..8cad9de 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,12 @@ -FROM registry.leenooks.net/leenooks/php:8.1-fpm-server +FROM registry.dege.au/leenooks/php:8.1-fpm-alpine-pgsql-server COPY . /var/www/html/ -RUN mkdir /var/www/.composer \ - && ([ -r auth.json ] && mv auth.json /var/www/.composer/) || true \ - && touch .composer.refresh \ - && mv .env.example .env \ - && FORCE_PERMS=1 NGINX_START=FALSE /sbin/init \ - && chmod +x /var/www/html/artisan /var/www/html/init-php.sh \ - && touch .migrate \ - && rm -rf /var/www/.composer/* +RUN mkdir -p ${COMPOSER_HOME} && \ + ([ -r auth.json ] && mv auth.json ${COMPOSER_HOME}) || true && \ + touch .composer.refresh && \ + mv .env.example .env && \ + FORCE_PERMS=1 NGINX_START=FALSE /sbin/init && \ + chmod +x /var/www/html/artisan /var/www/html/init-php.sh && \ + touch .migrate && \ + rm -rf ${COMPOSER_HOME}/*