Skip to content

Commit

Permalink
feat: add neos init for docker compose
Browse files Browse the repository at this point in the history
add neos init for docker compose
  • Loading branch information
erkenes committed Jul 17, 2024
1 parent e1d92e6 commit aa0d17c
Show file tree
Hide file tree
Showing 2 changed files with 246 additions and 6 deletions.
169 changes: 169 additions & 0 deletions .github/workflows/InitNeosCompose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
name: InitNeos

on:
workflow_call:
inputs:
compose_folder:
required: true
type: string
compose_service_name:
required: true
type: string
compose_service_user:
required: false
type: string
default: 'www-data'
url:
required: true
type: string
exec_clear_cache_warmup:
default: true
required: false
type: boolean
exec_migrate_database:
default: true
required: false
type: boolean
exec_publish_resource:
default: true
required: false
type: boolean
exec_command_migration:
default: false
required: false
type: boolean
exec_elasticsearch_index:
default: false
required: false
type: boolean
exec_elasticsearch_queue:
default: false
required: false
type: boolean
secrets:
HOST:
required: true
SSH_USERNAME:
required: true
SSH_KEY:
required: true
BASIC_AUTH_USERNAME:
required: false
BASIC_AUTH_PASSWORD:
required: false
jobs:
init:
runs-on: ubuntu-latest

steps:
- name: Check HTTP status
uses: gerdemann/http-status-code@main
with:
url: ${{ inputs.url }}
code: 200
timeout: 60
interval: 10
username: ${{ secrets.BASIC_AUTH_USERNAME }}
password: ${{ secrets.BASIC_AUTH_PASSWORD }}

- name: Clear cache and warmup cache
if: ${{ inputs.exec_clear_cache_warmup }}
uses: appleboy/ssh-action@029f5b4aeeeb58fdfe1410a5d17f967dacf36262
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
port: 22
timeout: "60s"
script: |
cd ${{ inputs.compose_folder }}/
docker compose exec -u ${{ inputs.compose_service_user }} ${{ inputs.compose_service_name }} sh -c "/data/flow flow:cache:flush && /data/flow flow:cache:warmup"
if [ $? != 0 ]
then
exit 1
fi
- name: Migrate database
if: ${{ inputs.exec_migrate_database }}
uses: appleboy/ssh-action@029f5b4aeeeb58fdfe1410a5d17f967dacf36262
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
port: 22
timeout: "60s"
script: |
cd ${{ inputs.compose_folder }}/
docker compose exec -u ${{ inputs.compose_service_user }} ${{ inputs.compose_service_name }} sh -c "/data/flow doctrine:migrate"
if [ $? != 0 ]
then
exit 1
fi
- name: Publish resources
if: ${{ inputs.exec_publish_resource }}
uses: appleboy/ssh-action@029f5b4aeeeb58fdfe1410a5d17f967dacf36262
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
port: 22
timeout: 120s
script: |
cd ${{ inputs.compose_folder }}/
docker compose exec -u ${{ inputs.compose_service_user }} ${{ inputs.compose_service_name }} sh -c "/data/flow flow:resource:publish --collection static"
if [ $? != 0 ]
then
exit 1
fi
- name: Execute Command Migrations
if: ${{ inputs.exec_command_migration }}
uses: appleboy/ssh-action@029f5b4aeeeb58fdfe1410a5d17f967dacf36262
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
port: 22
timeout: 120s
script: |
cd ${{ inputs.compose_folder }}/
docker compose exec -u ${{ inputs.compose_service_user }} ${{ inputs.compose_service_name }} sh -c "/data/flow commandmigration:migrate"
if [ $? != 0 ]
then
exit 1
fi
- name: Build Elasticsearch Index (Classic)
if: ${{ inputs.exec_elasticsearch_index }}
uses: appleboy/ssh-action@029f5b4aeeeb58fdfe1410a5d17f967dacf36262
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
port: 22
timeout: 120s
script: |
cd ${{ inputs.compose_folder }}/
docker compose exec -u ${{ inputs.compose_service_user }} ${{ inputs.compose_service_name }} sh -c "/data/flow nodeindex:build --workspace live"
if [ $? != 0 ]
then
exit 1
fi
- name: Build Elasticsearch Index (Queue)
if: ${{ inputs.exec_elasticsearch_queue }}
uses: appleboy/ssh-action@029f5b4aeeeb58fdfe1410a5d17f967dacf36262
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
port: 22
timeout: 120s
script: |
cd ${{ inputs.compose_folder }}/
docker compose exec -u ${{ inputs.compose_service_user }} ${{ inputs.compose_service_name }} sh -c "/data/flow nodeindexqueue:build --workspace live"
if [ $? != 0 ]
then
exit 1
fi
83 changes: 77 additions & 6 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

Execute Migrations and Commands after a deployment.

### Implementierung
### Implementation

#### With Container-Name

```yaml
# .github/workflows/deploy-to-live.yml
Expand All @@ -30,14 +32,61 @@ jobs:
key: ${{ secrets.AVENCY_SSH_KEY }}
```
### Inputs
The inputs are defined under `jobs.init.with`.
##### Special Inputs
#### containername
###### containername
The name of the appropriate container in which the commands should be executed.
#### InitNeos (Docker Composer)
```yaml
# .github/workflows/deploy-to-live.yml

jobs:
# [...]

init:
uses: avency/gh-workflows/.github/workflows/InitNeosCompose.yml@main
concurrency: deploy-to-live
with:
compose_folder: ${{ inputs.deployment-compose-target }}
compose_service_name: php
compose_service_user: www-data
url: https://${{ secrets.PROJECT_DOMAIN_LIVE }}/
exec_clear_cache_warmup: true
exec_migrate_database: true
exec_publish_resource: true
exec_command_migration: false
exec_elasticsearch_index: false
exec_elasticsearch_queue: false
secrets:
HOST: ${{ secrets.HOST }}
SSH_USERNAME: ${{ secrets.SSH_USERNAME }}
SSH_KEY: ${{ secrets.SSH_KEY }}
```
##### Special Inputs
###### compose_folder
The folder where the docker compose file is located.
###### compose_service_name
The name of the container (service) in which the commands should be executed.
###### compose_service_user
The name of the user who should execute the commands. (default: www-data)
##### Inputs
### Inputs
The inputs are defined under `jobs.init.with`.

#### url

The url with which the project can be accessed
Expand All @@ -64,4 +113,26 @@ Builds an ElasticSearch Index. Can not be used with `exec_elasticsearch_queue`.

#### exec_elasticsearch_queue

Builds an Elasticsearch Queue Index. Can not be used with `exec_elasticsearch_index`. [Requires additional Package](https://github.com/Flowpack/Flowpack.ElasticSearch.ContentRepositoryQueueIndexer)
Builds an Elasticsearch Queue Index. Can not be used with `exec_elasticsearch_index`. [Requires additional Package](https://github.com/Flowpack/Flowpack.ElasticSearch.ContentRepositoryQueueIndexer)

### Secrets

#### HOST:

The SSH Host name

#### SSH_USERNAME

Username for ssh.

#### SSH_KEY

SSH Key

#### BASIC_AUTH_USERNAME

If the host is protected with basic auth then you need to set the username.

#### BASIC_AUTH_PASSWORD

The password for the basic auth

0 comments on commit aa0d17c

Please sign in to comment.