-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: use hot cache instead of GitLab CI (#54r34g)
- Loading branch information
1 parent
b120277
commit fc909dd
Showing
6 changed files
with
106 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,59 @@ | ||
# Containerize a Dockerfile to the GitLab CI container registry. | ||
# The job name represents the folder in devops/docker/$CI_JOB_NAME/* | ||
# The job name represents the folder in devops/docker/$IMAGE_NAME/* | ||
# "only.changes" can not be extendable: https://gitlab.com/gitlab-org/gitlab/issues/8177 | ||
.containerize: | ||
stage: containerize | ||
image: | ||
# https://github.com/GoogleContainerTools/kaniko/issues/1002#issuecomment-578856209 | ||
# > This issue is only affecting people who are using the debug tag which is built on every commit to master. But still, use an explicit version! | ||
name: gcr.io/kaniko-project/executor:debug-v0.16.0 | ||
name: gcr.io/kaniko-project/executor:debug-v0.22.0 | ||
entrypoint: [""] | ||
cache: {} | ||
script: | ||
- export DOCKER_CONTAINER_FQN=$CI_REGISTRY_IMAGE/$CI_JOB_NAME:$CI_COMMIT_REF_SLUG | ||
- echo $DOCKER_CONTAINER_FQN | ||
# Always create a install.tar archive which contains all files relevant for installation | ||
- export INSTALL_FILES=$(ls -t $INSTALL_FILES 2>/dev/null) | ||
# Reset times for cache consistency | ||
- touch -a -m -t 201501010000.00 $INSTALL_FILES | ||
- tar -cvf install.tar $INSTALL_FILES | ||
# Create image name | ||
- export DOCKER_CONTAINER_FQN=$CI_REGISTRY_IMAGE/$IMAGE_NAME:$CI_COMMIT_REF_SLUG | ||
- echo Build as $DOCKER_CONTAINER_FQN | ||
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json | ||
- /kaniko/executor --cache=true --build-arg GL_CI_WORKDIR=$(realpath $CI_PROJECT_DIR) --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/devops/docker/$CI_JOB_NAME/Dockerfile --destination $DOCKER_CONTAINER_FQN | ||
- /kaniko/executor --cache=true --build-arg GL_CI_WORKDIR=$(realpath $CI_PROJECT_DIR) --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/devops/docker/$IMAGE_NAME/Dockerfile --destination $DOCKER_CONTAINER_FQN | ||
|
||
gitlab-ci: | ||
# Build an hot-cache image in a shared-runner environment | ||
gitlab-ci shared: | ||
extends: [.containerize] | ||
variables: | ||
IMAGE_NAME: gitlab-ci | ||
before_script: | ||
- "echo ########################" | ||
- echo Building and publishing docker images via GitLab shared runners is very slow. Please checkout this and setup your own runner | ||
- echo https://devowlio.gitbook.io/wp-react-starter/gitlab-integration/predefined-pipeline#disadvantages | ||
- "echo ########################" | ||
except: | ||
variables: | ||
- $DOCKER_DAEMON_ALLOW_UP | ||
only: | ||
changes: | ||
- package.json | ||
- yarn.lock | ||
- common/patch-package/* | ||
- "{packages,plugins}/*/{composer,package}.*" | ||
- devops/.gitlab/stage-containerize.yml | ||
- devops/docker/gitlab-ci/* | ||
|
||
# Build an hot-cache image in an own-runner environment | ||
# What's happening here? We are building the image only when changes | ||
# to non-dependency files are done. The dependencies are created and commit | ||
# through the `install` job. | ||
gitlab-ci hosted: | ||
extends: [.containerize] | ||
variables: | ||
IMAGE_NAME: gitlab-ci | ||
only: | ||
changes: | ||
- devops/.gitlab/stage-containerize.yml | ||
- devops/docker/gitlab-ci/* | ||
variables: | ||
- $DOCKER_DAEMON_ALLOW_UP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,23 @@ | ||
FROM php:7.3-cli-stretch | ||
FROM devowliode/wp-react-starter-gitlab-ci:php-7.3-cli-stretch | ||
|
||
# Avoid too many progress messages | ||
ENV CI=1 | ||
# Prepare our dependencies and cache | ||
ARG GL_CI_WORKDIR | ||
ENV CYPRESS_CACHE_FOLDER=/tmp$GL_CI_WORKDIR/.cypress | ||
ENV YARN_CACHE_FOLDER=/tmp$GL_CI_WORKDIR/.yarn | ||
|
||
# Set composer github token to avoid API rate limit (https://getcomposer.org/doc/articles/troubleshooting.md#api-rate-limit-and-oauth-tokens) | ||
ARG PHP_COMPOSER_GITHUB_TOKEN | ||
RUN (test $PHP_COMPOSER_GITHUB_TOKEN && \ | ||
composer config -g github-oauth.github.com $PHP_COMPOSER_GITHUB_TOKEN) || : | ||
|
||
# Install our dependencies into our gitlab runner | ||
WORKDIR /tmp$GL_CI_WORKDIR | ||
|
||
# Apt and common dependencies | ||
RUN apt-get update && apt-get install -y \ | ||
# Commons | ||
sudo \ | ||
autogen \ | ||
wget \ | ||
zip \ | ||
unzip \ | ||
tar \ | ||
git \ | ||
subversion \ | ||
build-essential \ | ||
apt-utils \ | ||
software-properties-common \ | ||
nasm \ | ||
libjpeg-dev \ | ||
libpng-dev \ | ||
libpng16-16 \ | ||
# Allow simple FTP uploads | ||
lftp \ | ||
wput \ | ||
# Pyhton is needed for Docker-Compose | ||
python \ | ||
python-pip \ | ||
python-dev \ | ||
# Cypress.io dependencies | ||
xvfb \ | ||
libgtk2.0-0 \ | ||
libgtk-3-0 \ | ||
libnotify-dev \ | ||
libgconf-2-4 \ | ||
libnss3 \ | ||
libxss1 \ | ||
libasound2 \ | ||
libxtst6 \ | ||
xauth \ | ||
# libssl-dev is needed for Phar (https://raspberrypi.stackexchange.com/a/36379) | ||
libssl-dev && \ | ||
# PHP dependencies (https://git.io/JvAFa) | ||
docker-php-ext-install -j4 phar json mbstring tokenizer && \ | ||
# xdebug (can be activated with `docker-php-ext-enable xdebug`, not by default because it slows down PHP) | ||
pecl install xdebug && \ | ||
# Composer | ||
curl -sS https://getcomposer.org/installer | php && \ | ||
mv composer.phar /usr/local/bin/composer && \ | ||
chmod +x /usr/local/bin/composer && \ | ||
composer self-update --preview && \ | ||
# Node | ||
curl -sL https://deb.nodesource.com/setup_12.x -o nodesource_setup.sh && \ | ||
bash nodesource_setup.sh && \ | ||
apt-get install -y nodejs && \ | ||
# Yarn | ||
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ | ||
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ | ||
apt-get update && apt-get install -y yarn && \ | ||
# Docker and Docker-Compose (via Python, PiP) | ||
curl -sSL https://get.docker.com/ | sh && \ | ||
pip install docker-compose && \ | ||
# WP CLI | ||
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar && \ | ||
php wp-cli.phar --info && \ | ||
chmod +x wp-cli.phar && \ | ||
mv wp-cli.phar /usr/local/bin/wp && \ | ||
# PHP Scoper | ||
curl -O -L https://github.com/humbug/php-scoper/releases/download/0.13.1/php-scoper.phar && \ | ||
chmod +x php-scoper.phar && \ | ||
mv php-scoper.phar /usr/local/bin/php-scoper | ||
COPY install.tar . | ||
|
||
RUN npm install -g \ | ||
# Global installations of npm packages | ||
wait-on | ||
# && \ | ||
# composer global require \ | ||
# Global installations of composer packages | ||
# hirak/prestissimo Prestissimo is currently not possible together with Lerna and CI due to a RC (https://git.io/JvPkZ)... wait for Composer v2 | ||
RUN tar -xvf install.tar && \ | ||
yarn bootstrap && \ | ||
yarn cypress install | ||
|
||
# Avoid too many progress messages | ||
ENV CI=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters