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

How to install the database for the official Drupal deploy image #357

Open
kopeboy opened this issue Dec 8, 2022 · 3 comments
Open

How to install the database for the official Drupal deploy image #357

kopeboy opened this issue Dec 8, 2022 · 3 comments

Comments

@kopeboy
Copy link

kopeboy commented Dec 8, 2022

I have just deployed the official awesome-akash Drupal image (which I guess is the same as the official Docker Drupal image), but when I head over to my provider's URL to install Drupal, I cannot setup the database.
Isn't the database setup included in the image?!
If it IS: where do I see/configure the database name/user/password?
If it is NOT: the pre-configured Drupal deployment is incomplete and doesn't work out of the box as is missing a database service.
image

@88plug
Copy link
Contributor

88plug commented Feb 27, 2023

Hi there! You can run the database in the same deployment. Here is what the YAML looks like to do that! Be sure to selected Advanced Options and change the Database Host to : db

---
version: "2.0"

services:
  drupal:
    image: drupal
    depends_on:
      - db
    expose:
      - port: 80
        to:
          - global: true
    env:
      - MYSQL_DATABASE_HOST=db
      - MYSQL_DATABASE_NAME=drupal
      - MYSQL_DATABASE_USER=myuser
      - MYSQL_DATABASE_PASSWORD=mypassword

  db:
    image: mysql:8
    env:
      - MYSQL_DATABASE=drupal
      - MYSQL_USER=myuser
      - MYSQL_PASSWORD=mypassword
      - MYSQL_RANDOM_ROOT_PASSWORD=yes
    expose:
      - port: 3306
        to:
          - service: drupal

profiles:
  compute:
    drupal:
      resources:
        cpu:
          units: 1.0
        memory:
          size: 1Gi
        storage:
          size: 1Gi
    db:
      resources:
        cpu:
          units: 0.5
        memory:
          size: 512Mi
        storage:
          size: 1Gi

  placement:
    akash:
      attributes:
        host: akash
      signedBy:
        anyOf:
          - "akash1365yvmc4s7awdyj3n2sav7xfx76adc6dnmlx63"
          - "akash18qa2a2ltfyvkyj0ggj3hkvuj6twzyumuaru9s4"
      pricing:
        drupal:
          denom: uakt
          amount: 10000
        db:
          denom: uakt
          amount: 5000

deployment:
  drupal:
    akash:
      profile: drupal
      count: 1
  db:
    akash:
      profile: db
      count: 1

@kopeboy
Copy link
Author

kopeboy commented Apr 17, 2023

Thanks. Is the storage defined like above persistent?
Also, how to provide the env variables in a secure way and ensure that the provider can never access them?

@88plug
Copy link
Contributor

88plug commented Apr 17, 2023

Thanks. Is the storage defined like above persistent?

No - you can add that as required easily with the SDL Builder by Cloudmos. Just import the above SDL.

Also, how to provide the env variables in a secure way and ensure that the provider can never access them?

Run a Hashivault Server and try this :

Create a policy in Vault to allow read access to the necessary secrets:

path "secret/data/db" {
  capabilities = ["read"]
}

This policy allows read access to the db secret. Create a role in Vault that maps to the policy:

$ vault write auth/token/roles/my-role allowed_policies=my-policy

This creates a role named my-role that maps to the my-policy policy. Create a token for the role:

$ vault token create -role=my-role

Now adapt the SDL to point at your Hashivault Server

version: "2.0"

services:
  drupal:
    image: drupal
    depends_on:
      - db
    expose:
      - port: 80
        to:
          - global: true
    environment:
      - MYSQL_DATABASE_HOST=db
      - MYSQL_DATABASE_NAME=drupal
      - MYSQL_DATABASE_USER=${MYSQL_USER}
      - MYSQL_DATABASE_PASSWORD=${MYSQL_PASSWORD}
    command: ["sh", "-c", "export MYSQL_USER=$(curl --header 'X-Vault-Token: $VAULT_TOKEN' --request GET $VAULT_ADDRESS/v1/secret/data/db | sed -e 's/^.*MYSQL_USER": "\(.*\)", "MYSQL_PASSWORD.*$/\1/'); export MYSQL_PASSWORD=$(curl --header 'X-Vault-Token: $VAULT_TOKEN' --request GET $VAULT_ADDRESS/v1/secret/data/db | sed -e 's/^.*MYSQL_PASSWORD": "\(.*\)".*$/\1/'); apache2-foreground"]
    env:
      VAULT_TOKEN: <VAULT_TOKEN>
      VAULT_ADDRESS: <VAULT_ADDRESS>

  db:
    image: mysql:8
    environment:
      - MYSQL_DATABASE=drupal
      - MYSQL_USER=${MYSQL_USER}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
      - MYSQL_RANDOM_ROOT_PASSWORD=yes
    expose:
      - port: 3306
        to:
          - service: drupal
    command: ["sh", "-c", "export MYSQL_USER=$(curl --header 'X-Vault-Token: $VAULT_TOKEN' --request GET $VAULT_ADDRESS/v1/secret/data/db | sed -e 's/^.*MYSQL_USER": "\(.*\)", "MYSQL_PASSWORD.*$/\1/'); export MYSQL_PASSWORD=$(curl --header 'X-Vault-Token: $VAULT_TOKEN' --request GET $VAULT_ADDRESS/v1/secret/data/db | sed -e 's/^.*MYSQL_PASSWORD": "\(.*\)".*$/\1/'); docker-entrypoint.sh mysqld"]
    env:
      VAULT_TOKEN: <VAULT_TOKEN>
      VAULT_ADDRESS: <VAULT_ADDRESS>

profiles:
  compute:
    drupal:
      resources:
        cpu:
          units: 1.0
        memory:
          size: 1Gi
        storage:
          size: 1Gi
    db:
      resources:
        cpu:
          units: 0.5
        memory:
          size: 512Mi
        storage:
          size: 1Gi

  placement:
    akash:
      attributes:
        host: akash
      signedBy:
        anyOf:
          - "akash1365yvmc4s7awdyj3n2sav7xfx76adc6dnmlx63"
          - "akash18qa2a2ltfyvkyj0ggj3hkvuj6twzyumuaru9s4"
      pricing:
        drupal:
          denom: uakt
          amount: 10000
        db:
          denom: uakt
          amount: 5000

deployment:
  drupal:
    akash:
      profile: drupal
      count: 1
  db:
    akash:
      profile: db
      count: 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants