Commit 290c70b2 authored by Aurelien's avatar Aurelien
Browse files

Merge branch '389-new-job-composer_migrate' into 'latest'

Resolve "[New Job] - Artisan_migrate"

Closes #389

See merge request r2devops/hub!218
parents 495edbef 4a6a3490
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@ bom
bulary
bundler
Bzip
cd
CD
cdxgen
cfg
cfn
@@ -23,6 +25,8 @@ changelogs
checkov
checkstyle
ChkTex
ci
CI
cli
clj
CNIL
+41 −0
Original line number Diff line number Diff line
## Objective

This job will allow you to migrate the database using a migration file that you already have in `database/migrations`, and it provides an artifact with all the logs at the end

## How to use it

!!! info
    You can use this job with all Data Base Management Systems (MySQL, PostgreSQL ...), you just need to link your remote database in the environment variables file, so make sure that you are using the correct database credentials.
    

1. Ensure that your project has a pre-made environment file such as `.env.testing` in example, which contains the variables that will be used by the project.
2. Add this job URL inside the `include` list of your `.gitlab-ci.yml` file (see the [quick setup](/use-the-hub/#quick-setup)). You can specify [a fixed version](#changelog) instead of `latest`.
    ```yaml
      - remote: 'https://jobs.r2devops.io/latest/artisan_migrate.yml'
    ```
3. If you need to customize the job (stage, variables, ...) 👉 check the [jobs
   customization](/use-the-hub/#jobs-customization)
4. Well done, your job is ready to work ! 😀


## Job details

* Job name: `artisan_migrate`
* Default stage: `build`
* Docker image: [`edbizarro/gitlab-ci-pipeline-php:7.3`](https://hub.docker.com/r/edbizarro/gitlab-ci-pipeline-php){:target="_blank"}
* When: `always`


### Variables

| Name | Default | Description |
| ---- | ------- | --------------- |
| `PROJECT_ROOT` | `.` | Path to the directory containing environment variables |
| `ENV_NAME` | `.env.testing` | Name of the environment variables file to use | 
| `ARTISAN_MIGRATE_OPTIONS` | ` ` | Options for command `php artisan migrate` |
| `ARTISAN_OUTPUT` | `artisan_migration.log` | Name for logs file |


### Artifact

When the job is done, the command output will be available under the file name `ARTISAN_OUTPUT` as an artifact.
 No newline at end of file
+26 −0
Original line number Diff line number Diff line
# Job from R2Devops hub --> r2devops.io

stages:
  - build

artisan_migrate:
  stage: build
  image:
    name: edbizarro/gitlab-ci-pipeline-php:7.3
    entrypoint: [""]
  variables:
    PROJECT_ROOT: "."
    ENV_NAME: ".env.testing"
    ARTISAN_MIGRATE_OPTIONS: ""
    ARTISAN_OUTPUT: "artisan_migration.log"
  script:
    # Working directory
    - cd $PROJECT_ROOT
    # Setup .env
    - cp -f ${ENV_NAME} .env
    # Run the migration
    - php artisan migrate ${ARTISAN_MIGRATE_OPTIONS} >&1 | tee ${ARTISAN_OUTPUT}
  artifacts:
    expose_as: "artisan migration"
    paths:
      - "${ARTISAN_OUTPUT}"
+14 −0
Original line number Diff line number Diff line
name: artisan_migrate
description: A ready-to-use job for migrating your database
default_stage: build
icon: 🗃️
maintainer: moha-s
license: MIT
images:
    "edbizarro/gitlab-ci-pipeline-php": "7.3"
tools:
labels:
    - GitLab
    - PHP
    - Artisan
    - Database
+0 −0

Empty file added.

Loading