Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker Build Again #704

Merged
merged 63 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
3b9364c
Remove composer update hook to run it in control site. Side effects.
jonpugh Jan 19, 2023
516f201
put back bin-tools so they are available in bin/
jonpugh Jan 19, 2023
1b21026
Put back docker build command
jonpugh Jan 19, 2023
67b5125
Go back to calling the container the "server"
jonpugh Jan 19, 2023
c6fb965
committing old docker-systemd-prepare file
jonpugh Jan 19, 2023
d90516a
Add ubuntu20 functions to systemd prepare
jonpugh Jan 19, 2023
999f68b
Adding run-quiet script to main scripts.
jonpugh Jan 19, 2023
72936a4
attempting again
jonpugh Jan 19, 2023
f4be26d
Run both devshop-install-prerequisites (to install ansible) AND docke…
jonpugh Jan 19, 2023
e32eb50
Rename back to devshop.server.
jonpugh Jan 19, 2023
b7a79c2
Default to ubuntu2004 when using docker/docker-compose.yml
jonpugh Jan 19, 2023
e8e302b
Change back to devshop.container in github actions.
jonpugh Jan 19, 2023
3bfd041
Fix 2004 script.
jonpugh Jan 19, 2023
619f0ab
run quiet in 1804
jonpugh Jan 19, 2023
adf7df7
Default to 18 in the docker compose file for now, that one works.
jonpugh Jan 19, 2023
deec0af
Change container service name.
jonpugh Jan 19, 2023
52b71a2
Full path to entrypoint.
jonpugh Jan 19, 2023
0a47658
Wrong place for stuff.
jonpugh Jan 19, 2023
9318355
Include missing env vars in docker compose.
jonpugh Jan 19, 2023
d97fcb2
Add back entrypoint from old branch.
jonpugh Jan 19, 2023
500c08a
Add back entrypoint from old branch.
jonpugh Jan 19, 2023
443d54a
Restoring our ARGs and ENVs.
jonpugh Jan 19, 2023
276e49d
Run composer install devshop as devshop user, to prevent git from cal…
jonpugh Jan 19, 2023
7edc7ad
Include ANSIBLE_PLAYBOOK_COMMAND_OPTIONS
jonpugh Jan 19, 2023
4b4b40c
Add --scratch option to robo build command to use ubuntu FROM.
jonpugh Jan 19, 2023
24e53f5
Set ANSIBLE_PLAYBOOK_COMMAND_OPTIONS_ARG so it gets picked up on dock…
jonpugh Jan 19, 2023
b6fe3c8
Clean up pre-req scripts trying to get ubuntu 20 to work.
jonpugh Jan 19, 2023
9cd3540
Gather git info about the repo.
jonpugh Jan 19, 2023
58e2f0c
Rm -rf so that we are sure it's a fresh devshop.
jonpugh Jan 19, 2023
164db42
Set DEVSHOP_CONTAINER_FROM ubuntu18.04 by default.
jonpugh Jan 19, 2023
2b0d890
Fix `robo build` and `robo build --scratch` commands.
jonpugh Jan 19, 2023
7cf682c
Pass extra vars in robofile to set devshop_version.
jonpugh Jan 19, 2023
1f59267
Chown the entire directory to aegir_user.
jonpugh Jan 19, 2023
55e69bd
Revert running composer as aegir user... maybe it only was dubious be…
jonpugh Jan 19, 2023
c6ef50c
Use docker-compose inspect in case container fails.
jonpugh Jan 19, 2023
e150fdb
Ensure devshop source is owned by user who will run composer install.
jonpugh Jan 19, 2023
46bb968
Proper docker inspect.
jonpugh Jan 19, 2023
2f05d6a
Output docker ps in Review Container step in github actions.
jonpugh Jan 19, 2023
2826e7c
Set DEVSHOP_DOCKER_IMAGE: "devshop/server:${{ matrix.os }}" so that g…
jonpugh Jan 19, 2023
8b027b8
Set COMPOSE_FILE to avoid including .override w/volumes.
jonpugh Jan 19, 2023
d3a838f
Fix robo exec command.
jonpugh Jan 19, 2023
566dc35
Just testing using gg image.
jonpugh Jan 19, 2023
7313348
Wait 5 seconds for systemd?
jonpugh Jan 19, 2023
d8f5f80
Default to ubuntu:1804 in dockerfile, but allow .env to override it.
jonpugh Jan 19, 2023
04b7476
Attempting to revert github actions to working state, from 1.8.x branch.
jonpugh Jan 19, 2023
a361a12
switch to gg container. Removes need for pre-req install.
jonpugh Jan 19, 2023
e485b08
Set ANSIBLE_PLAYBOOK_COMMAND_OPTIONS locally to load development vars.
jonpugh Jan 19, 2023
a4e367c
Use $DEVSHOP_DOCKER_COMMAND_RUN if no other command specified.
jonpugh Jan 19, 2023
3b6ea37
Go back to ubuntu. With GG, GITHUB ACTIONS fails on mysql! msg: Ser…
jonpugh Jan 19, 2023
3ef12dd
Go back to ubuntu. With GG, GITHUB ACTIONS fails on mysql! msg: Ser…
jonpugh Jan 19, 2023
7898c90
Opts for up and build commands must match.
jonpugh Jan 19, 2023
950e048
Remove funky path stuff from devshop-* scripts... the new composer pa…
jonpugh Jan 19, 2023
277514a
Attempting to get working on github actions https://github.com/geerli…
jonpugh Jan 19, 2023
fa71a46
Trying another way.
jonpugh Jan 19, 2023
5433dc2
Attempt to set cgroup: host to fix this nightmare.
jonpugh Jan 19, 2023
086ebcc
Revert "Attempt to set cgroup: host to fix this nightmare."
jonpugh Jan 19, 2023
edeabde
add rw
jonpugh Jan 19, 2023
304a337
Set runs-on to fix to ubuntu 20.
jonpugh Jan 19, 2023
dfa611d
Removing volumes to test this guys theory: https://github.com/geerlin…
jonpugh Jan 19, 2023
fb3dc96
Removing volumes to test this guys theory: https://github.com/geerlin…
jonpugh Jan 19, 2023
a6bccea
Fix bad --from option.
jonpugh Jan 19, 2023
48702cd
Pass DEVSHOP_DOCKER_COMMAND_RUN to docker container through docker-co…
jonpugh Jan 19, 2023
cdd0416
Remove paths on install containers as well.
jonpugh Jan 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions .github/workflows/devshop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
env:
# Set ANSIBLE_VERBOSITY to 1,2 or 3 when needed for development.
ANSIBLE_VERBOSITY: 0
DEBUG_COMMAND: "docker-compose exec -T container systemctl status --no-pager"
DEBUG_COMMAND: "docker-compose exec -T devshop.server systemctl status --no-pager"
GITHUB_TOKEN: ${{ secrets.INPUT_GITHUB_TOKEN }}
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_PR_SHA: ${{ github.event.pull_request.head.sha }}
Expand All @@ -23,9 +23,13 @@ env:
DOCKER_COMMAND_POST: "echo 'GitHub Actions Container was launched.'"

# Load vars from the vars.ci.yml file.
ANSIBLE_PLAYBOOK_COMMAND_OPTIONS_ARG: "--extra-vars=@/usr/share/devshop/vars.ci.yml"
ANSIBLE_PLAYBOOK_COMMAND_OPTIONS: "--extra-vars=@/usr/share/devshop/vars.ci.yml"
GIT_REF: 1.x

# Prevents including docker-compose.override, which is for local development.
COMPOSE_FILE: docker-compose.yml

jobs:
docker:
name: "Build DevShop"
Expand All @@ -40,13 +44,14 @@ jobs:

os:
- 'ubuntu1804'
- 'ubuntu2004'
# - 'ubuntu2004'
env:
OS: "${{ matrix.os }}"
DEVSHOP_DOCKER_IMAGE: "devshop/server:${{ matrix.os }}"
HOSTNAME: "devshop.${{ github.event.pull_request.number }}.${{ matrix.os }}.actions.github.com"
ANSIBLE_EXTRA_VARS: "${{ matrix.vars }}"

runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
# By default, actions/checkout uses the current SHA for the branch it is testing. See on.push.branches: 1.x
# https://github.com/opendevshop/devshop/runs/1517209717?check_suite_focus=true#step:2:465
Expand All @@ -70,42 +75,45 @@ jobs:
echo "devshop_version: ${{ github.head_ref }}" >> vars.ci.yml
echo "devshop_cli_repo: ${{ github.event.pull_request.head.repo.clone_url }}" >> vars.ci.yml
echo "GIT_REF=${{ github.head_ref }}" >> $GITHUB_ENV
echo "ANSIBLE_VERBOSITY=2" >> $GITHUB_ENV
git switch --create ${{ github.head_ref }}
# If you need really big logs...
# echo "ANSIBLE_VERBOSITY=2" >> $GITHUB_ENV

# Build "base"
- name: "Build devshop/container"
# Build "devshop.server"
- name: "Build devshop/server:${{ matrix.os }}"
working-directory: docker
run: docker-compose build

# Launch Container
- name: "Launch a freshly built devshop/container:${{ matrix.os }} container"
- name: "Launch a freshly built devshop/server:${{ matrix.os }} container"
working-directory: docker
# -f is used to skip loading docker-compose.override.yml
run: |
docker-compose -f docker-compose.yml up --detach
docker-compose up --detach devshop.server
sleep 3
docker-compose logs
docker-compose exec -T container devshop-logo "GitHub Actions Container populated with code. Running SHA ${GITHUB_PR_SHA}"s
docker-compose exec -T devshop.server /usr/share/devshop/scripts/devshop-logo "GitHub Actions Container populated with code. Running SHA ${GITHUB_PR_SHA}"

- name: "Review Container Environment"
working-directory: docker
run: |
docker-compose exec -T container env
docker-compose exec -T container systemctl status --no-pager
docker-compose ps -a
docker ps -a
docker inspect docker_devshop.server_1
docker-compose exec -T devshop.server env
docker-compose exec -T devshop.server systemctl status --no-pager
sleep 4

- name: "Install DevShop (devshop.server/play.yml --tags=runtime)"
working-directory: docker

# Since the container is launched with a new DEVSHOP_DOCKER_COMMAND_RUN, run the default.
run: |
docker-compose exec -T container devshop-ansible-playbook
docker-compose exec -T devshop.server bash -c '${DEFAULT_DEVSHOP_DOCKER_COMMAND_RUN}'

- name: "Test DevShop"
working-directory: docker
run: docker-compose exec -T --user aegir container /usr/share/devshop/tests/devshop-tests.sh
run: docker-compose exec -T --user aegir devshop.server /usr/share/devshop/tests/devshop-tests.sh

- name: Save Docker Logs as Artifacts
working-directory: docker
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/install-sh-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ docker run \
--hostname $DEVSHOP_SERVER_HOSTNAME \
--publish 80:80 \
--volume $PWD/build/install.sh:/tmp/devshop-install.sh \
--volume /sys/fs/cgroup:/sys/fs/cgroup:ro \
ubuntu/container

docker exec \
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ jobs:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0

- name: Build Install Script
run: make build
working-directory: install

- name: Run Install Script
run: bash .github/workflows/install-sh-test.sh

Expand Down
70 changes: 48 additions & 22 deletions RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class RoboFile extends \Robo\Tasks {
'run-command' => 'DEVSHOP_DOCKER_COMMAND_RUN',

// Used in docker compose image.
'from' => 'FROM_IMAGE',
'from' => 'DEVSHOP_CONTAINER_FROM',
'os' => 'OS_VERSION',
'dockerfile' => 'DOCKERFILE',
'compose-file' => 'COMPOSE_FILE',
Expand Down Expand Up @@ -226,7 +226,8 @@ public function prepareSourcecode($opts = [
* @param folder The folder to run 'docker-compose build' in. Use "all" to build in folder 'docker', then 'roles'.
* @param service The service to build. passed to 'docker-compose build $SERVICE'. Use "all" to build all services.
*
* @option $tag The string to tag the resulting container with.
* @option $docker-image The label to use when building or running the container.
* @option $scratch Set --scratch to set docker-image=ubuntu2004
* @option $from The image to use to build the docker image FROM. Ignored if "os" is set.
* @option $os An OS "slug" for any of the geerlingguy/docker-*-ansible images: https://hub.docker.com/u/geerlingguy/
* @option $vars Ansible vars to pass to --extra-vars option.
Expand All @@ -238,7 +239,8 @@ public function prepareSourcecode($opts = [
*/
public function build($folder = 'docker', $service = 'all', $opts = [
'docker-image' => 'devshop/server:latest',
'from' => NULL,
'scratch' => FALSE,
'from' => 'ubuntu:18.04',
'build-command' => NULL,
'os' => NULL,
'vars' => '',
Expand All @@ -249,6 +251,16 @@ public function build($folder = 'docker', $service = 'all', $opts = [
'install-at-runtime' => FALSE,
]) {

try {
$branch = $this->getRepository()->getCurrentBranch();
$remote = $this->getRepository()->getCurrentRemoteName();
$remote_url = $this->getRepository()->getCurrentRemoteUrl();
$this->say("Current code branch <comment>{$branch}</comment> remote {$remote_url}");
} catch (\Exception $e) {
$this->io()->error("No upstream configured for branch '$branch'. Please set one with the command 'git branch --track $branch' or 'git push -u origin $branch'");
exit(1);
}

if ($service == "all") {
$service = '';
}
Expand All @@ -260,7 +272,11 @@ public function build($folder = 'docker', $service = 'all', $opts = [

// Define docker-image (name for the "image" in docker-compose)
// Set FROM_IMAGE and DEVSHOP_DOCKER_IMAGE if --os option is used. (and --from was not used)
if (empty($opts['from']) && $opts['os'] !== NULL) {
if ($opts['scratch']) {
$opts['from'] = "ubuntu:18.04";
}

if ($opts['os'] !== NULL) {
$opts['from'] = "geerlingguy/docker-{$opts['os']}-ansible";
$opts['docker-image'] = 'devshop/server:' . $opts['os'];
}
Expand Down Expand Up @@ -289,6 +305,11 @@ public function build($folder = 'docker', $service = 'all', $opts = [
// Runtime Environment for the docker-compose build command.
$env_build = $this->generateEnvironmentArgs($opts);

$env_build['ANSIBLE_EXTRA_VARS'] = "devshop_version={$branch} devshop_cli_version={$branch}";
$env_build['ANSIBLE_PLAYBOOK_COMMAND_OPTIONS_ARG'] = '--extra-vars=@/usr/share/devshop/vars.development.yml';

print_r($env_build);

$provision_io = new \DevShop\Component\PowerProcess\PowerProcessStyle($this->input(), $this->output());
$process = new \DevShop\Component\PowerProcess\PowerProcess("docker-compose build --no-cache $service", $provision_io);
$process->setEnv($env_build);
Expand Down Expand Up @@ -387,7 +408,7 @@ public function up($docker_command = '/usr/share/devshop/scripts/devshop-ansible
'docker-image' => 'devshop/server:latest',
// The OS "slug" to use instead of devshop/server:ubuntu1804. If specified, "docker-image" option will be ignored.
'os' => NULL,
'from' => NULL,
'from' => 'ubuntu:18.04',
'vars' => '',
'tags' => '',
'skip-tags' => '',
Expand Down Expand Up @@ -472,7 +493,7 @@ public function up($docker_command = '/usr/share/devshop/scripts/devshop-ansible
$opts['from'] = "geerlingguy/docker-{$opts['os']}-ansible";
$opts['docker-image'] = 'devshop/server:' . $opts['os'];
}
else {
elseif (empty($opts['from'])) {
$opts['from'] = $opts['docker-image'];
}

Expand Down Expand Up @@ -534,7 +555,7 @@ public function up($docker_command = '/usr/share/devshop/scripts/devshop-ansible
$test_command = '';
if ($opts['test']) {
// Do not run a playbook on docker-compose up, because it will launch as a separate process and we won't know when it ends.
$cmd[] = "docker-compose run container {$docker_command}";
$cmd[] = "docker-compose run devshop.server {$docker_command}";
$env_run['DEVSHOP_DOCKER_COMMAND_RUN'] = $docker_command;

$test_command = "su aegir --command /usr/share/devshop/tests/devshop-tests.sh";
Expand All @@ -546,7 +567,7 @@ public function up($docker_command = '/usr/share/devshop/scripts/devshop-ansible
$test_command = "/usr/share/devshop/tests/devshop-tests-upgrade.sh";
}
else {
$cmd[] = "docker-compose up --detach --force-recreate container";
$cmd[] = "docker compose up --detach --force-recreate devshop.server";
if (!$opts['no-follow']) {
$cmd[] = "docker-compose logs -f";
}
Expand All @@ -557,6 +578,9 @@ public function up($docker_command = '/usr/share/devshop/scripts/devshop-ansible

// Runtime Environment for the $cmd list.
$env_run = $this->generateEnvironmentArgs($opts);
$env_run['ANSIBLE_PLAYBOOK_COMMAND_OPTIONS'] = '--extra-vars=@/usr/share/devshop/vars.development.yml';
print_r($env_run);

$extra_vars = array();

// Set devshop_version and cli_repo here because every local dev environment is different.
Expand Down Expand Up @@ -650,13 +674,15 @@ private function optionsToArray($options_list) {
/**
* Run a command in the devshop container.
*/
public function exec($cmd = '', $opts = ['user' => 'aegir']) {
return $this->_exec("docker-compose exec -T \
public function exec($cmd = '', $opts = ['user' => 'root']) {
return $this->taskExec("docker-compose exec -T \
--env ANSIBLE_TAGS=runtime \
--env ANSIBLE_SKIP_TAGS \
--env ANSIBLE_VARS \
--user {$opts['user']} \
devshop $cmd")->getExitCode();
devshop.server $cmd")
->dir('docker')
->run();
}

/**
Expand All @@ -681,13 +707,13 @@ public function destroy($opts = ['force' => 0]) {
// Remove devmaster site folder
$version = self::DEVSHOP_LOCAL_VERSION;
$uri = self::DEVSHOP_LOCAL_URI;
$this->_exec("cd docker && docker-compose exec container rm -rf /usr/share/devshop/src/DevShop/Control/web/sites/{$uri}");
$this->_exec("cd docker && docker-compose exec devshop.server rm -rf /usr/share/devshop/src/DevShop/Control/web/sites/{$uri}");
$this->_exec('cd docker && docker-compose kill');
$this->_exec('cd docker && docker-compose rm -fv');
}

// Don't run when -n is specified,
if (!$this->input()->isInteractive() || $this->confirm("Destroy container home directory? (aegir-home)")) {
if (!$this->input()->isInteractive() || $this->confirm("Destroy devshop.server home directory? (aegir-home)")) {
if ($this->_exec("rm -rf aegir-home")->wasSuccessful()) {
$this->say("Entire aegir-home folder deleted.");
}
Expand Down Expand Up @@ -732,7 +758,7 @@ public function logs() {
*/
public function watchdog() {
$user = 'aegir';
$this->taskExec("docker-compose exec --user $user -T container drush @hostmaster wd-show --tail --extended")
$this->taskExec("docker-compose exec --user $user -T devshop.server drush @hostmaster wd-show --tail --extended")
->dir("docker")
->run();
}
Expand All @@ -754,10 +780,10 @@ public function restart() {
public function shell($user = 'aegir') {

if ($user) {
$process = new \Symfony\Component\Process\Process("docker-compose exec --user $user container bash");
$process = new \Symfony\Component\Process\Process("docker-compose exec --user $user devshop.server bash");
}
else {
$process = new \Symfony\Component\Process\Process("docker-compose exec container bash");
$process = new \Symfony\Component\Process\Process("docker-compose exec devshop.server bash");
}
$process->setTty(TRUE);
$process->setTimeout(NULL);
Expand All @@ -779,16 +805,16 @@ public function test($user = 'aegir', $opts = array(
// If running in CI, create the test-artifacts directory and ensure ownership first.
// @TODO: Move logic to a special CI container.
if (!empty($_SERVER['CI'])) {
$commands[] = "docker-compose exec $no_tty container mkdir -p /var/aegir/test-artifacts";
$commands[] = "docker-compose exec $no_tty container chown aegir:aegir /var/aegir/test-artifacts -R";
$commands[] = "docker-compose exec $no_tty container chmod 777 /var/aegir/test-artifacts -R";
$commands[] = "docker-compose exec $no_tty devshop.server mkdir -p /var/aegir/test-artifacts";
$commands[] = "docker-compose exec $no_tty devshop.server chown aegir:aegir /var/aegir/test-artifacts -R";
$commands[] = "docker-compose exec $no_tty devshop.server chmod 777 /var/aegir/test-artifacts -R";
}

if ($opts['reinstall']) {
$commands[] = "docker-compose exec $no_tty --user $user container drush @hostmaster provision-install --force-reinstall";
$commands[] = "docker-compose exec $no_tty --user $user devshop.server drush @hostmaster provision-install --force-reinstall";
}

$commands[] = "docker-compose exec $no_tty --user $user container /usr/share/devshop/tests/devshop-tests.sh";
$commands[] = "docker-compose exec $no_tty --user $user devshop.server /usr/share/devshop/tests/devshop-tests.sh";
$provision_io = new \DevShop\Component\PowerProcess\PowerProcessStyle($this->input, $this->output);
foreach ($commands as $command) {
$process = new \DevShop\Component\PowerProcess\PowerProcess($command, $provision_io);
Expand All @@ -815,7 +841,7 @@ public function test($user = 'aegir', $opts = array(
* Get a one-time login link to Devamster.
*/
public function login($user = 'aegir') {
$this->taskExec("docker-compose exec --user $user -T container /usr/share/devshop/bin/drush @hostmaster uli")
$this->taskExec("docker-compose exec --user $user -T devshop.server /usr/share/devshop/bin/drush @hostmaster uli")
->dir("docker")
->run();
;
Expand Down
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"drupal/provision": "4.x-dev",
"psr/cache": "^1.0",
"symfony/deprecation-contracts": "^2.5",
"symfony/options-resolver": "^4.4"
"symfony/options-resolver": "^4.4",
"devshop/bin-tools": "1.x-dev"
},
"replace": {
"drupal/drupal": "*"
Expand All @@ -45,6 +46,10 @@
"type": "composer",
"url": "https://packages.drupal.org/7"
},
{
"type": "path",
"url": "scripts"
},
{
"type": "path",
"url": "src/DevShop/Component/ComposerCommon"
Expand Down Expand Up @@ -117,9 +122,6 @@
"post-install-cmd": [
"DevShop\\Composer::installControl"
],
"post-update-cmd": [
"DevShop\\Composer::updateControl"
],
"roles:update": [
"DevShop\\Composer::updateRoles"
]
Expand Down
Loading