Skip to content

Setup the repo

Setup the repo #30

Workflow file for this run

#
# This workflow is for testing your server's config.
#
# It will launch a docker-based test server, run your ansible playbook, and launch a site with ddev.
#
# This allows you to create pull requests to alter server config, with CI/CD to ensure it works.
#
name: Server Test
on:
pull_request:
env:
# To install github runners automatically, you need a personal access token with admin:write permissions on your repository.
RUNNER_GITHUB_TOKEN: "${{ secrets.OUR_GITHUB_TOKEN_RUNNER_ADMIN }}"
# The playbook to run.
# You can use the one included in the site-runn ansible roles or make your own.
# ANSIBLE_PLAYBOOK: ansible/site-runner/playbook.yml
ANSIBLE_PLAYBOOK: ansible/playbook.example.yml
RUNNER_NAME: platform@server.mydomain.com
concurrency:
group: ${{ github.workflow }}-${{ github.event.number }}
cancel-in-progress: true
jobs:
create-server:
name: Launch test runner
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
submodules: 'recursive'
# run-with-summary, etc
- uses: jonpugh/goatscripts@main
- name: Install docker-compose
uses: KengoTODA/actions-setup-docker-compose@v1
with:
version: '2.24.0'
- name: Information
run: |
docker-compose --version
# Site runner ansible roles now sets SSH config to allow hosts to become known on first connection.
- name: Set ansible variables
run: |
echo "operations_platform_ssh_private_key: \"${{ secrets.SSH_PRIVATE_KEY }}\"" > vars.ci.yml
cat vars.ci.yml
- name: Set runner name
if: github.event_name == 'pull_request'
run: |
echo "OPERATIONS_ENVIRONMENT_NAME=server.pr${{ github.event.number }}.${{ matrix.os }}.server.mydomain.com" >> "$GITHUB_ENV"
- name: Set variables
run: |
echo "DOCKER_HOSTNAME=${{ env.OPERATIONS_ENVIRONMENT_NAME }}" > .env
- name: Start Containers
run: |
docker compose up -d --quiet-pull
docker-compose exec operations chmod 0400 /etc/shadow
- name: Inventory
run: |
run-with-summary \
docker-compose exec operations \
ansible-playbook ${ANSIBLE_PLAYBOOK} --list-hosts
env:
SUCCESS: "Ansible inventory"
ERROR: "Ansible inventory list failed"
HIDE: true
- name: Playbook
env:
SUCCESS: "Ansible playbook completed successfully."
ERROR: "Ansible playbook failed!"
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
run: |
run-with-summary \
docker-compose exec operations \
ansible-playbook ${ANSIBLE_PLAYBOOK} \
--extra-vars operations_github_api_token=${RUNNER_GITHUB_TOKEN}
- name: Run jobs
env:
REPO: ${{ github.repository }}
RUN_ID: ${{ github.run_id }}
ATTEMPT: ${{ github.run_attempt }}
JOB_NAME: ${{ github.job }}
GH_TOKEN: ${{ github.token }}
TIMEOUT: 600
run: |
wait-for ./scripts/jobs-done
create-site:
name: Create Preview Site
uses: operations-project/github-action-ddev-runner/.github/workflows/operations.site.deploy.ddev.yml@feature/reusable-workflows
with:
# Configure your site here.
git_root: /var/platform/Sites/${{ github.repository }}/pr${{ github.event.number }}
# Use the http URL.
git_repository: ${{ github.event.repository.clone_url }}
# Must be unique per server.
ddev_project_name: ourproject.pr${{ github.event.number }}
# Used to create a system domain.
ddev_project_tld: sites.server.mydomain.com
# Tell the remote workflow what to run on.
github_runs_on: platform@server.mydomain.com
# Define the github environment name, to be displayed in the UI.
github_environment_name: pr${{ github.event.number }}
# Define a github environment url, a link to be shown on the pull request.
github_environment_url: http://pr${{ github.event.number }}.sites.server.mydomain.com
# To persist a site's data, set "run_prepare_command" to false.
run_prepare_command: true
prepare_command: echo "Preparing site..."
# Command to run after deploying code.
deploy_command: ddev exec echo "Hello from $(hostname)!"
# Additional ddev config to apply to the environment.
# Will be saved to .ddev/config.zzz.runner.yaml
ddev_config: |
additional_fqdns:
- admin.pr${{ github.event.number }}.sites.server.mydomain.com
- ddev-runner.ddev.site
run-command:
name: DDEV Status
uses: operations-project/github-action-ddev-runner/.github/workflows/operations.site.command.yml@feature/reusable-workflows
needs: create-site
with:
working_directory: /var/platform/Sites/${{ github.repository }}/pr${{ github.event.number }}
github_runs_on: platform@server.mydomain.com
command: ddev status
env: |
SUCCESS="DDEV Status"
HIDE=1
test-site:
name: Run tests
needs: create-site
runs-on: platform@server.mydomain.com
steps:
- uses: jonpugh/goatscripts@main
- name: Check homepage for Hello World.
env:
SUCCESS: "Tests passed! DDEV webserver is online. :boom:"
ERROR: "Unable to load DDEV website. :x:"
run: |
run-with-summary curl https://ddev-runner.ddev.site
curl -s https://ddev-runner.ddev.site | grep "Hello World!"
remove-site:
name: Remove Site
uses: operations-project/github-action-ddev-runner/.github/workflows/operations.site.destroy.ddev.yml@feature/reusable-workflows
needs: test-site
with:
git_root: /var/platform/Sites/${{ github.repository }}/pr${{ github.event.number }}
github_runs_on: platform@server.mydomain.com