Skip to content

Commit

Permalink
some more deletes
Browse files Browse the repository at this point in the history
  • Loading branch information
milesstoetzner committed Sep 4, 2024
1 parent fcc659f commit 4a25402
Show file tree
Hide file tree
Showing 2 changed files with 185 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,74 @@ const generator: ImplementationGenerator = {
reason: 'One-time use docker container ("fake Kubernetes job") with imperative parts, while other technologies provide declarative modules.',

generate: (name, type) => {
const AnsibleTouchJobTask = {
name: 'touch compose',
register: 'compose',
'ansible.builtin.tempfile': {
suffix: '{{ SELF.database_name }}-{{ HOST.dbms_name }}.database.compose.yaml',
},
}

const AnsibleCreateJobTask = (query: string) => {
return {
name: 'create compose',
'ansible.builtin.copy': {
dest: '{{ compose.path }}',
content: '{{ manifest | to_yaml }}',
},
vars: {
manifest: {
name: '{{ SELF.database_name }}-{{ HOST.dbms_name }}-database-job',
services: {
job: {
container_name: '{{ SELF.database_name }}-{{ HOST.dbms_name }}-database-job',
image: 'mysql:{{ HOST.dbms_version }}',
network_mode: 'host',
command: [
'mysql',
'--host={{ HOST.management_address }}',
'--port={{ HOST.management_port }}',
'--user=root',
'--password={{ HOST.dbms_password }}',
'-e',
query,
],
},
},
},
},
}
}

const AnsibleApplyJobTasks = [
{
name: 'apply compose',
'ansible.builtin.shell': 'docker compose -f {{ compose.path }} up -d',
args: {
executable: '/usr/bin/bash',
},
environment: {
...AnsibleDockerHostEnvironment(),
},
},
{
name: 'give job some time',
'ansible.builtin.pause': {
seconds: 10,
},
},
{
name: 'unapply compose',
'ansible.builtin.shell': 'docker compose -f {{ compose.path }} down',
args: {
executable: '/usr/bin/bash',
},
environment: {
...AnsibleDockerHostEnvironment(),
},
},
]

return {
derived_from: name,
metadata: {
Expand All @@ -36,74 +104,31 @@ const generator: ImplementationGenerator = {
inputs: {
playbook: {
q: [
{
name: 'touch compose',
register: 'compose',
'ansible.builtin.tempfile': {
suffix: '{{ SELF.database_name }}-{{ HOST.dbms_name }}.database.compose.yaml',
},
},
{
name: 'create compose',
'ansible.builtin.copy': {
dest: '{{ compose.path }}',
content: '{{ manifest | to_yaml }}',
},
vars: {
manifest: {
name: '{{ SELF.database_name }}-{{ HOST.dbms_name }}-database-job',
services: {
job: {
container_name:
'{{ SELF.database_name }}-{{ HOST.dbms_name }}-database-job',
image: 'mysql:{{ HOST.dbms_version }}',
network_mode: 'host',
command: [
'mysql',
'--host={{ HOST.management_address }}',
'--port={{ HOST.management_port }}',
'--user=root',
'--password={{ HOST.dbms_password }}',
'-e',
"CREATE DATABASE IF NOT EXISTS {{ SELF.database_name }}; CREATE USER IF NOT EXISTS '{{ SELF.database_user }}'@'%' IDENTIFIED BY '{{ SELF.database_password }}'; GRANT ALL PRIVILEGES ON *.* TO '{{ SELF.database_user }}'@'%';",
],
},
},
},
},
},
{
name: 'apply compose',
'ansible.builtin.shell': 'docker compose -f {{ compose.path }} up -d',
args: {
executable: '/usr/bin/bash',
},
environment: {
...AnsibleDockerHostEnvironment(),
},
},
{
name: 'give job some time',
'ansible.builtin.pause': {
seconds: 10,
},
},
{
name: 'unapply compose',
'ansible.builtin.shell': 'docker compose -f {{ compose.path }} down',
args: {
executable: '/usr/bin/bash',
},
environment: {
...AnsibleDockerHostEnvironment(),
},
},
AnsibleTouchJobTask,
AnsibleCreateJobTask(
"CREATE DATABASE IF NOT EXISTS {{ SELF.database_name }}; CREATE USER IF NOT EXISTS '{{ SELF.database_user }}'@'%' IDENTIFIED BY '{{ SELF.database_password }}'; GRANT ALL PRIVILEGES ON *.* TO '{{ SELF.database_user }}'@'%';"
),
...AnsibleApplyJobTasks,
],
},
},
},
delete: {
implementation: {
...AnsibleOrchestratorOperation(),
},
inputs: {
playbook: {
q: [
AnsibleTouchJobTask,
AnsibleCreateJobTask(
"DROP USER IF EXISTS '{{ SELF.database_user }}'@'%'; DROP DATABASE IF EXISTS {{ SELF.database_name }};"
),
...AnsibleApplyJobTasks,
],
},
},
},
// TODO: delete
delete: 'exit 0',
},
},
},
Expand Down
Loading

0 comments on commit 4a25402

Please sign in to comment.