Skip to content

Commit

Permalink
Merge pull request #403 from govCMS/fix/buildx-base-image
Browse files Browse the repository at this point in the history
Update CI pipeline.
  • Loading branch information
steveworley authored May 23, 2024
2 parents e88e103 + f509163 commit 996b237
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 36 deletions.
58 changes: 31 additions & 27 deletions .ahoy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ commands:
up:
usage: Build project.
cmd: |
docker-compose up -d "$@" &&
docker-compose exec -T test dockerize -wait tcp://mariadb:3306 -timeout 2m;
docker compose up -d "$@" &&
docker compose exec -T test dockerize -wait tcp://mariadb:3306 -timeout 2m;
down:
usage: Delete project.
cmd: docker-compose down
cmd: docker compose down

build:
usage: Build project locally (single-local architecture only).
Expand All @@ -19,15 +19,15 @@ commands:
if [ "$1" == "y" ]; then
env $(cat .env | grep -v "#" | xargs) docker buildx bake -f docker-compose.yml --no-cache cli --load
env $(cat .env | grep -v "#" | xargs) docker buildx bake -f docker-compose.yml --load
docker-compose up -d
docker-compose exec -T test dockerize -wait tcp://mariadb:3306 -timeout 2m
docker compose up -d
docker compose exec -T test dockerize -wait tcp://mariadb:3306 -timeout 2m
else
ahoy confirm "Are you sure environment variables are correct? Update .env if not." &&
# Run this if confirm returns true
env $(cat .env | grep -v "#" | xargs) docker buildx bake -f docker-compose.yml --no-cache cli --load &&
env $(cat .env | grep -v "#" | xargs) docker buildx bake -f docker-compose.yml --load &&
docker-compose up -d "$@" &&
docker-compose exec -T test dockerize -wait tcp://mariadb:3306 -timeout 2m ||
docker compose up -d "$@" &&
docker compose exec -T test dockerize -wait tcp://mariadb:3306 -timeout 2m ||
# Run this if confirm returns false
echo "OK, nothing to do."
fi
Expand All @@ -51,51 +51,48 @@ commands:
cli:
usage: Start a shell inside TEST container.
cmd: docker-compose exec cli bash
cmd: docker compose exec cli bash

run:
usage: Run command inside TEST container.
cmd: docker-compose exec -T cli bash -c "$@"
cmd: docker compose exec -T cli bash -c "$@"

drush:
usage: Run drush commands in TEST container.
cmd: docker-compose exec -T cli drush "$@"
cmd: docker compose exec -T cli drush "$@"

logs:
usage: Show Docker logs.
cmd: docker-compose logs "$@"
cmd: docker compose logs "$@"

ps:
usage: List running Docker containers.
cmd: docker-compose ps
cmd: docker compose ps

restart:
usage: Restart Docker containers.
cmd: docker-compose restart
cmd: docker compose restart

stop:
usage: Stop Docker containers.
cmd: docker-compose stop "$@"
cmd: docker compose stop "$@"

install:
usage: Install the profile.
cmd: docker-compose exec -T cli drush si -y govcms "$@"
cmd: docker compose exec -T cli drush si -y govcms "$@"

login:
usage: Login to a website.
cmd: docker-compose exec -T cli drush uli "$@"
cmd: docker compose exec -T cli drush uli "$@"

pull:
usage: Pull latest docker images.
cmd: docker image ls --format \"{{.Repository}}:{{.Tag}}\" | grep govcms/ | grep -v none | xargs -n1 docker pull | cat

audit-site:
usage: Run site audit
cmd: docker-compose exec -T cli drutiny profile:run d8-full @self "$@"

lint:
usage: Lint code
cmd: docker-compose exec cli lint-govcms
cmd: docker compose exec cli lint-govcms

test:
usage: Run all tests.
Expand All @@ -105,26 +102,31 @@ commands:
test-behat:
usage: Run Behat tests.
cmd: docker-compose exec cli behat "$@"
cmd: docker compose exec cli behat "$@"

test-phpunit:
usage: Run PHPUnit tests.
cmd: docker-compose exec cli phpunit --testsuite govcms
cmd: docker compose exec cli phpunit --testsuite govcms

test-redis:
usage: Verify redis can accept connections.
cmd: |
ahoy -v install
docker-compose exec -T --env ENABLE_REDIS=true cli drush status
if [ $(docker-compose exec -T redis redis-cli KEYS '*' | wc -l) -le 1 ]; then
docker compose exec -T --env ENABLE_REDIS=true cli drush status
if [ $(docker compose exec -T redis redis-cli KEYS '*' | wc -l) -le 1 ]; then
echo 'Redis fail: No valid cache keys.'
exit 1
else
echo "Redis success: Redis contains $redisKeys keys."
fi
test-goss:
usage: Validate images with dgoss.
cmd: ./tests/goss/run_all.sh
cmd: |
curl -L https://github.com/goss-org/goss/releases/latest/download/goss-linux-amd64 -o /usr/local/bin/goss
chmod +rx /usr/local/bin/goss
curl -L https://github.com/goss-org/goss/releases/latest/download/dgoss -o /usr/local/bin/dgoss
chmod +rx /usr/local/bin/dgoss
./tests/goss/run_all.sh
test-install:
usage: Test a blank install.
Expand All @@ -133,8 +135,10 @@ commands:
test-nginx:
usage: Validate the nginx image.
cmd: |
docker-compose exec -T test dockerize -wait tcp://nginx:8080 -timeout 1m
docker-compose exec -T nginx nginx -t
apk update && apk add --no-cache php php-phar php-json php-openssl php-mbstring php-dom php-tokenizer php-xml php-xmlwriter
curl -sS https://getcomposer.org/installer -o composer-setup.php && php composer-setup.php --install-dir=/usr/local/bin --filename=composer && rm composer-setup.php
docker compose exec -T test dockerize -wait tcp://nginx:8080 -timeout 1m
docker compose exec -T nginx nginx -t
composer validate --strict -d .docker/images/nginx/tests
composer install -d .docker/images/nginx/tests
.docker/images/nginx/tests/vendor/bin/phpunit -c .docker/images/nginx/tests/phpunit.xml
Expand Down
27 changes: 20 additions & 7 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
image: gitlab-registry-production.govcms.amazee.io/govcms/govcms-ci/govcms-ci-buildx
image: docker:26.1.3-cli

services:
- name: gitlab-registry-production.govcms.amazee.io/govcms/govcms-ci/dind:latest
- name: docker:26.1.3-dind
command: ["--tls=false"]

stages:
Expand Down Expand Up @@ -32,9 +32,9 @@ workflow:
variables:
DEPLOY_TAG: $CI_COMMIT_TAG

- if: $CI_COMMIT_REF_NAME =~ /feature/
- if: $CI_COMMIT_REF_NAME =~ /^(feature|feat|fix)/
variables:
DEPLOY_TAG: "9.x-dev"
DEPLOY_TAG: "10.x-dev"

- when: always # Run the pipeline in other cases

Expand All @@ -48,12 +48,19 @@ workflow:
DOCKER_HOST: tcp://localhost:2375
BUILDKIT_INLINE_CACHE: '1'
DOCKER_DRIVER: overlay2
GOSS_FILES_STRATEGY: cp

.before_script_build: &before_script_build
before_script:
- if [ -z "$DEPLOY_TAG" ]; then echo "DEPLOY_TAG must be set for an actionable build."; exit 1; fi
# Latest tags need a confirmation var (provided manually: DEPLOY_LATEST)
- if [[ "$DEPLOY_TAG" == "10.x-latest" ]] && [ -z "$DEPLOY_LATEST" ]; then echo "DEPLOY_LATEST must be set to progress with 'latest' tags."; exit 1; fi
# Install ahoy into the runner image.
- |
os=$(uname -s | tr [:upper:] [:lower:]) && architecture=$(case $(uname -m) in x86_64 | amd64) echo "amd64" ;; aarch64 | arm64 | armv8) echo "arm64" ;; *) echo "amd64" ;; esac) \
&& wget -q https://github.com/ahoy-cli/ahoy/releases/download/v2.1.1/ahoy-bin-$os-$architecture -O /usr/local/bin/ahoy \
&& chmod +x /usr/local/bin/ahoy
- apk add bash curl
- cp .env.default .env
- sed -i -e "s/^GOVCMS_RELEASE_TAG.*/GOVCMS_RELEASE_TAG=$DEPLOY_TAG/" .env
# Determine and use latest distribution release branch if USE_LATEST_RELEASE_BRANCH is set
Expand All @@ -67,15 +74,21 @@ workflow:
sed -i -e "s#^GOVCMS_PROJECT_VERSION.*#GOVCMS_PROJECT_VERSION=dev-$LATEST#" .env
fi
- cat .env
- update-binfmts --enable # Important: Ensures execution of other binary formats is enabled in the kernel
- export $(grep -v '^#' .env | xargs)
- docker network prune -f && docker network inspect amazeeio-network >/dev/null || docker network create amazeeio-network
- docker login -u $DOCKER_USER -p $DOCKER_PASS
- composer config github-oauth.github.com "$GITHUB_TOKEN"
- |
cat << EOF > auth.json
{
"github-oauth": {
"github.com": "$GITHUB_TOKEN"
}
}
EOF
- docker swarm init
- docker secret create composer-auth auth.json
- ahoy --version
- ahoy build y
- docker image list

# ---
# Job Definitions
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.0'

# Mount for easier dev
x-volumes: &default-volumes
volumes:
Expand Down

0 comments on commit 996b237

Please sign in to comment.