Mappia on Gitlab CI
This document describes how to containerize Magento 2 using Gitlab's CI and the Docker hub registry.
yml
container:
stage: build
image: docker:latest
variables:
BASE_IMAGE_FPM: mappia/magento-php:8.1-fpm-alpine-v0.4.0
BASE_IMAGE_CLI: mappia/magento-php:8.1-cli-alpine-v0.4.0
DOCKER_BUILDKIT: 1
before_script:
- docker login -u gitlab-ci-token -p ${CI_BUILD_TOKEN} ${CI_REGISTRY}
- >
echo '{
"config": {
"gitlab-domain": "'${GITLAB_DOMAIN}'"
}
}' > config.json
- >
echo '{
"http-basic": {
"repo.magento.com": {
"username": "'${COMPOSER_REPO_MAGENTO_USERNAME}'",
"password": "'${COMPOSER_REPO_MAGENTO_PASSWORD}'"
}
},
"gitlab-token": {
"'${GITLAB_DOMAIN}'": "'${CI_BUILD_TOKEN}'"
}
}' > auth.json
- docker pull -q ${BASE_IMAGE_FPM}
- docker pull -q ${BASE_IMAGE_CLI}
script:
- export DOCKER_BUILDKIT=1
- export DOCKER_CLI_EXPERIMENTAL=enabled
- docker build . -f path/to/Dockerfile
--secret id=composer.auth,src=auth.json
--secret id=composer.config,src=config.json
-t ${DOCKER_IMAGE_TAG}-fpm
--build-arg BASE_IMAGE=${BASE_IMAGE_FPM}
- docker build src/ -f path/to/Dockerfile
--secret id=composer.auth,src=auth.json
--secret id=composer.config,src=config.json
-t ${DOCKER_IMAGE_TAG}-cli
--build-arg BASE_IMAGE=${BASE_IMAGE_CLI}
- docker push --quiet ${DOCKER_IMAGE_TAG}-fpm
- docker push --quiet ${DOCKER_IMAGE_TAG}-cli
after_script:
- docker logout ${CI_REGISTRY}
- rm -f auth.json config.json