From 14e73dfe2032388c692689a597377f7ce437bed2 Mon Sep 17 00:00:00 2001 From: Lacey Sanderson Date: Wed, 1 May 2024 16:52:52 -0600 Subject: [PATCH 01/20] Update docker to Ubuntu 24.04 and Flyway 10.12.0 --- docker/Dockerfile | 33 +++++++++++++++------------------ docker/entrypoint.sh | 2 ++ docker/flyway.conf | 6 ------ docker/flyway.toml | 12 ++++++++++++ 4 files changed, 29 insertions(+), 24 deletions(-) delete mode 100644 docker/flyway.conf create mode 100644 docker/flyway.toml diff --git a/docker/Dockerfile b/docker/Dockerfile index 6a0c9780..ee6865d3 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,13 +1,12 @@ -FROM ubuntu:20.04 -MAINTAINER Scott Cain +FROM ubuntu:24.04 + +ARG CHADO_VERSION='1.31' RUN apt-get update #for some reason, this has to be installed by itself RUN apt-get install -y tzdata - RUN apt-get install -y apt-utils - RUN apt-get install -y wget \ unzip \ git \ @@ -19,27 +18,25 @@ RUN apt-get install -y wget \ RUN apt-get install -y postgresql-all RUN cd /usr/local \ - && wget -qO- https://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/8.5.2/flyway-commandline-8.5.2-linux-x64.tar.gz | tar xvz \ - && ln -s `pwd`/flyway-8.5.2/flyway /usr/local/bin + && wget -qO- https://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/10.12.0/flyway-commandline-10.12.0-linux-x64.tar.gz | tar xvz \ + && ln -s `pwd`/flyway-10.12.0/flyway /usr/local/bin -ARG CHADO_BRANCH=${CHADO_BRANCH} -ARG CHADO_VERSION=${CHADO_VERSION} - -RUN cd / \ - && git clone https://github.com/GMOD/Chado.git \ - && cd Chado \ - && git checkout ${CHADO_BRANCH} +COPY . /Chado RUN /etc/init.d/postgresql start \ && su -c "createdb chado" - postgres \ - && su -c "psql chado < /Chado/chado/schemas/${CHADO_VERSION}/default_schema.sql" - postgres \ + && su -c "psql chado < /Chado/schemas/${CHADO_VERSION}/default_schema.sql" - postgres \ && su -c "psql -c \"ALTER USER postgres PASSWORD 'chadotest';\"" - postgres \ && /etc/init.d/postgresql stop; -ADD flyway.conf /root/flyway.conf -ADD entrypoint.sh entrypoint.sh -ADD motd /etc/motd +WORKDIR /Chado/docker +RUN cp flyway.toml /root/flyway.toml \ + && cp entrypoint.sh /usr/bin/entrypoint.sh \ + && chmod +x /usr/bin/entrypoint.sh \ + && cp motd /etc/motd + +WORKDIR /Chado RUN echo '[ ! -z "$TERM" -a -r /etc/motd ] && cat /etc/issue && cat /etc/motd' >> /etc/bash.bashrc -ENTRYPOINT ["sh", "entrypoint.sh"] +ENTRYPOINT ["entrypoint.sh"] diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index f97dd545..763617bf 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -1,2 +1,4 @@ +#!/bin/bash /etc/init.d/postgresql start +flyway baseline /bin/bash diff --git a/docker/flyway.conf b/docker/flyway.conf deleted file mode 100644 index 47496f0f..00000000 --- a/docker/flyway.conf +++ /dev/null @@ -1,6 +0,0 @@ -flyway.url=jdbc:postgresql://localhost:5432/chado -flyway.user=postgres -flyway.password=chadotest -flyway.schemas=public -flyway.locations=filesystem:/Chado -flyway.validateOnMigrate=false diff --git a/docker/flyway.toml b/docker/flyway.toml new file mode 100644 index 00000000..70c25d59 --- /dev/null +++ b/docker/flyway.toml @@ -0,0 +1,12 @@ +# More information on the parameters can be found here: +# https://documentation.red-gate.com/flyway/flyway-cli-and-api/configuration/parameters + +[environments.core] +url = "jdbc:postgresql://localhost:5432/chado" +user = "postgres" +password = "chadotest" +schemas = ["public"] + +[flyway] +environment = "core" +locations = ["filesystem:/Chado"] From 625bd9455bfe0194e8a40d8a2cb6c58ed08448dc Mon Sep 17 00:00:00 2001 From: Lacey Sanderson Date: Wed, 1 May 2024 18:42:46 -0600 Subject: [PATCH 02/20] Fix syntax errors caused by incorrectly formatted comments. --- chado/migrations/V1.3.3.011__fix_db_relationship_type_id.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chado/migrations/V1.3.3.011__fix_db_relationship_type_id.sql b/chado/migrations/V1.3.3.011__fix_db_relationship_type_id.sql index 4d3aafb8..0b5456d7 100644 --- a/chado/migrations/V1.3.3.011__fix_db_relationship_type_id.sql +++ b/chado/migrations/V1.3.3.011__fix_db_relationship_type_id.sql @@ -1,4 +1,4 @@ - +/* Delete the improperly added foreign key from v1.3.3.002 */ ALTER TABLE db_relationship DROP CONSTRAINT db_relationship_type_id_fkey; - +/* Add it back in with type_id => cvterm.cvterm_id as it should have */ ALTER TABLE db_relationship ADD CONSTRAINT db_relationship_type_id_fkey FOREIGN KEY (type_id) REFERENCES cvterm(cvterm_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED; From 6de6f4b31edcbc5018aa6305cc9bd4e0e4959e06 Mon Sep 17 00:00:00 2001 From: Lacey-Anne Sanderson Date: Wed, 1 May 2024 18:56:32 -0600 Subject: [PATCH 03/20] Create ALL-testMigrate.yml --- .github/workflows/ALL-testMigrate.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/ALL-testMigrate.yml diff --git a/.github/workflows/ALL-testMigrate.yml b/.github/workflows/ALL-testMigrate.yml new file mode 100644 index 00000000..fc9b8fb1 --- /dev/null +++ b/.github/workflows/ALL-testMigrate.yml @@ -0,0 +1,27 @@ +name: Testing Flyway Migrations +on: + workflow_dispatch: + pull_request: + types: [opened, synchronize] + +jobs: + run-tests: + runs-on: ubuntu-latest + + steps: + # Check out the repo + - name: Checkout Repository + uses: actions/checkout@v4 + # Here we fully build a docker using the current checked out code + # to ensure we have not broken the install/build process. + - name: Build Docker Image + run: | + docker build --tag gmod/chado:local --file docker/Dockerfile ./ + # Just spin up docker the good ol' fashion way. + - name: Spin up Local Docker + run: | + docker run --name=chadodocker -tid gmod/chado:local + # Runs the PHPUnit tests. + - name: Run Flyway Migrations + run: | + docker exec chadodocker flyway migrate From 3c06260974b2a97014083f11563a52de020f7b31 Mon Sep 17 00:00:00 2001 From: Lacey-Anne Sanderson Date: Wed, 1 May 2024 19:10:48 -0600 Subject: [PATCH 04/20] Add flyway migrate even though the docker init script should have. --- .github/workflows/ALL-testMigrate.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ALL-testMigrate.yml b/.github/workflows/ALL-testMigrate.yml index fc9b8fb1..8ef2a014 100644 --- a/.github/workflows/ALL-testMigrate.yml +++ b/.github/workflows/ALL-testMigrate.yml @@ -24,4 +24,5 @@ jobs: # Runs the PHPUnit tests. - name: Run Flyway Migrations run: | + docker exec chadodocker flyway baseline docker exec chadodocker flyway migrate From 071716dce153a4afcf0140fdabcd938dd8109ac0 Mon Sep 17 00:00:00 2001 From: Lacey-Anne Sanderson Date: Wed, 1 May 2024 19:19:27 -0600 Subject: [PATCH 05/20] Run all in the same step in case there are issues with our docker keeping postgresql going. --- .github/workflows/ALL-testMigrate.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ALL-testMigrate.yml b/.github/workflows/ALL-testMigrate.yml index 8ef2a014..6bc4baa7 100644 --- a/.github/workflows/ALL-testMigrate.yml +++ b/.github/workflows/ALL-testMigrate.yml @@ -13,16 +13,14 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 # Here we fully build a docker using the current checked out code - # to ensure we have not broken the install/build process. + # to ensure we test the current migrations. - name: Build Docker Image run: | docker build --tag gmod/chado:local --file docker/Dockerfile ./ - # Just spin up docker the good ol' fashion way. - - name: Spin up Local Docker + # Just spin up docker the good ol' fashion way + # then run flyway baseline and migrate. + - name: Run Flyway Baseline then migrate run: | docker run --name=chadodocker -tid gmod/chado:local - # Runs the PHPUnit tests. - - name: Run Flyway Migrations - run: | docker exec chadodocker flyway baseline docker exec chadodocker flyway migrate From da736628015d96b0f66d1d87fcba46ea8f2fc51d Mon Sep 17 00:00:00 2001 From: Lacey Sanderson Date: Wed, 1 May 2024 19:43:20 -0600 Subject: [PATCH 06/20] Add arg so we can build specific postgresql versions. --- docker/Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index ee6865d3..524d1bb5 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,6 +1,7 @@ FROM ubuntu:24.04 ARG CHADO_VERSION='1.31' +ARG PGSQL_VERSION='16' RUN apt-get update @@ -15,7 +16,9 @@ RUN apt-get install -y wget \ vim \ uuid-dev -RUN apt-get install -y postgresql-all +RUN apt-get install -y postgresql-common \ + && /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y \ + && apt-get install -y postgresql-${PGSQL_VERSION} RUN cd /usr/local \ && wget -qO- https://repo1.maven.org/maven2/org/flywaydb/flyway-commandline/10.12.0/flyway-commandline-10.12.0-linux-x64.tar.gz | tar xvz \ From 4525a2272e530182eda47473bc1f5e29e9cd4259 Mon Sep 17 00:00:00 2001 From: Lacey-Anne Sanderson Date: Wed, 1 May 2024 19:51:03 -0600 Subject: [PATCH 07/20] Matrix the testing workflow for postgresql version --- .github/workflows/ALL-testMigrate.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ALL-testMigrate.yml b/.github/workflows/ALL-testMigrate.yml index 6bc4baa7..687ff5a2 100644 --- a/.github/workflows/ALL-testMigrate.yml +++ b/.github/workflows/ALL-testMigrate.yml @@ -8,6 +8,15 @@ jobs: run-tests: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + pgsql-version: + - "12" + - "13" + - "14" + - "15" + - "16" steps: # Check out the repo - name: Checkout Repository @@ -16,7 +25,9 @@ jobs: # to ensure we test the current migrations. - name: Build Docker Image run: | - docker build --tag gmod/chado:local --file docker/Dockerfile ./ + docker build --tag gmod/chado:local \ + --file docker/Dockerfile \ + --build-arg PGSQL_VERSION="${{ matrix.pgsql-version }}" ./ # Just spin up docker the good ol' fashion way # then run flyway baseline and migrate. - name: Run Flyway Baseline then migrate From a3b820ff1166dc6d053354e403c38c95b0301f1f Mon Sep 17 00:00:00 2001 From: Lacey Sanderson Date: Wed, 1 May 2024 20:08:57 -0600 Subject: [PATCH 08/20] Update readme with new docker instructions. --- README.md | 49 ++++++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 540337f2..7f4d6b85 100644 --- a/README.md +++ b/README.md @@ -85,20 +85,21 @@ install the Chado schema. ### Using the Chado Docker Image #### Locally Build the Docker Image -To build the docker image run the following: +To build the docker image using the default values, run the following command: ```bash - -cd docker -make v +docker build --tag gmod/chado:local --file docker/Dockerfile ./ +``` +If you would like to build a docker that uses a specific version of PostgreSQL then you can run the following command instead. In this case you will replace `` with the version of PostgreSQL. We currently support 12, 13, 14, 15, and 16. +```bash +docker build --tag gmod/chado:local --file docker/Dockerfile --build-arg PGSQL_VERSION= ./ ``` -Replace `` with a specific version of Chado that you want to use (e.g. `1.31`). This will create a Docker image with the tag: `gmod/chado:` where is the same version used above (e.g. `gmod/chado:1.31`). #### Using the Chado Docker You can start and work within the Chado container by using the following command. ```bash -docker run -it gmod/chado: +docker run -it gmod/chado:local ``` -Replace `` with the specific version of Chado that you want to use (e.g. `1.31`). This will start the PostgreSQL server and give you access to a bash terminal. +This will start the PostgreSQL server and give you access to a bash terminal within the docker container. As a test, you can run the `flyway info` command after starting the container: @@ -114,33 +115,27 @@ psql -U postgres -h localhost -d chado You will be prompted for a password. The default password is `chadotest` ##### Testing a Pull Request -You can test any pull request or other Git branch of Chado by navigating to the Chado directory in the image and changing the branch: +When you build the image as shown above, it actually uses the current code in your Chado clone. +In order to allow you to modify the migrations while running the container, you will mount your current directory inside the container using the following approach. This way you can edit the files locally and they will be automatically updated within the container and available to flyway. ```bash -cd Chado/chado -git checkout +docker build --tag gmod/chado:local --file docker/Dockerfile --build-arg PGSQL_VERSION= ./ +docker run -it -rm --volume=$(pwd):/Chado gmod/chado:local ``` -If the branch has any FlyWay migrations you can test those by running these flyway commans: +You can test FlyWay migrations by running these flyway commands: -Use this command to see what needs to be applied -```bash -flyway info -``` + - See what migrations need to be applied: -For testing of a PR you can set the baseline to the current installation of Chado provided by the image: -```bash -flyway baseline -``` + ```bash + flyway info + ``` -To update Chado you can apply the Flyway migrations: -```bash -flyway migrate -``` + - Run the migrations available: -As long as no errors occured you will see success for all updates: + ```bash + flyway migrate + ``` -```bash -flyway info -``` +The migrations have been applied correctly if you do not see any red errors. However, it is good practice to run `flyway info` again to confirm. From 672df4b75d43d6b02bbf10da9f6d663013a9f8db Mon Sep 17 00:00:00 2001 From: Lacey-Anne Sanderson Date: Wed, 1 May 2024 20:11:52 -0600 Subject: [PATCH 09/20] make command more readable. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7f4d6b85..d5e73e18 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,8 @@ You will be prompted for a password. The default password is `chadotest` When you build the image as shown above, it actually uses the current code in your Chado clone. In order to allow you to modify the migrations while running the container, you will mount your current directory inside the container using the following approach. This way you can edit the files locally and they will be automatically updated within the container and available to flyway. ```bash -docker build --tag gmod/chado:local --file docker/Dockerfile --build-arg PGSQL_VERSION= ./ +docker build --tag gmod/chado:local --file docker/Dockerfile \ + --build-arg PGSQL_VERSION= ./ docker run -it -rm --volume=$(pwd):/Chado gmod/chado:local ``` You can test FlyWay migrations by running these flyway commands: From 50c11428cac9efcca3606e19744b5124c616b0e1 Mon Sep 17 00:00:00 2001 From: Lacey-Anne Sanderson Date: Thu, 2 May 2024 10:16:50 -0600 Subject: [PATCH 10/20] Create workflow to build github packages. --- .github/workflows/PRs-buildDocker.yml | 65 +++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 .github/workflows/PRs-buildDocker.yml diff --git a/.github/workflows/PRs-buildDocker.yml b/.github/workflows/PRs-buildDocker.yml new file mode 100644 index 00000000..9150a514 --- /dev/null +++ b/.github/workflows/PRs-buildDocker.yml @@ -0,0 +1,65 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +# GitHub recommends pinning actions to a commit SHA. +# To get a newer version, you will need to update the SHA. +# You can also reference a tag or branch, but the action may change without warning. + +name: Publish Docker image +on: + workflow_dispatch: + pull_request: + types: [opened, synchronize] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + push_to_registry: + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + attestations: write + + steps: + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Log in to Docker Hub + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + id: push + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: . + push: true + build-args: | + PGSQL_VERSION=16 + file: 'docker/Dockerfile' + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + + - name: Generate artifact attestation + uses: actions/attest-build-provenance@v1 + with: + subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} + subject-digest: ${{ steps.push.outputs.digest }} + push-to-registry: true + From 36c34e8361d31f1e18002c2655d9048b64e1eb1e Mon Sep 17 00:00:00 2001 From: Lacey-Anne Sanderson Date: Thu, 2 May 2024 10:27:42 -0600 Subject: [PATCH 11/20] Missed the id-token permission. --- .github/workflows/PRs-buildDocker.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/PRs-buildDocker.yml b/.github/workflows/PRs-buildDocker.yml index 9150a514..ab0f081f 100644 --- a/.github/workflows/PRs-buildDocker.yml +++ b/.github/workflows/PRs-buildDocker.yml @@ -24,6 +24,7 @@ jobs: permissions: packages: write contents: read + id-token: write attestations: write steps: From e8398fa98141351a0eb6fac2daa7b8b45dcf6060 Mon Sep 17 00:00:00 2001 From: Lacey-Anne Sanderson Date: Thu, 2 May 2024 10:50:02 -0600 Subject: [PATCH 12/20] Image name needs to be all lowercase. --- .github/workflows/PRs-buildDocker.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/PRs-buildDocker.yml b/.github/workflows/PRs-buildDocker.yml index ab0f081f..0ae9ef8c 100644 --- a/.github/workflows/PRs-buildDocker.yml +++ b/.github/workflows/PRs-buildDocker.yml @@ -30,6 +30,9 @@ jobs: steps: - name: Check out the repo uses: actions/checkout@v4 + - name: Make Image Name all lowercase + run: | + echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV} - name: Log in to Docker Hub uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 From 14d01d36741c462500658f4acd302e0d70b6f104 Mon Sep 17 00:00:00 2001 From: Lacey-Anne Sanderson Date: Thu, 2 May 2024 10:56:43 -0600 Subject: [PATCH 13/20] Remove attestation and is makes an unreadable image tag --- .github/workflows/PRs-buildDocker.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/workflows/PRs-buildDocker.yml b/.github/workflows/PRs-buildDocker.yml index 0ae9ef8c..04f502c0 100644 --- a/.github/workflows/PRs-buildDocker.yml +++ b/.github/workflows/PRs-buildDocker.yml @@ -59,11 +59,3 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - - - name: Generate artifact attestation - uses: actions/attest-build-provenance@v1 - with: - subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} - subject-digest: ${{ steps.push.outputs.digest }} - push-to-registry: true - From e7a935cda8aae12668a86fa778a1659f78365f0b Mon Sep 17 00:00:00 2001 From: Lacey Sanderson Date: Thu, 2 May 2024 11:27:23 -0600 Subject: [PATCH 14/20] Update README to reference pulling pre-built images. --- README.md | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index d5e73e18..9100b042 100644 --- a/README.md +++ b/README.md @@ -83,23 +83,21 @@ are currently using PostgreSQL. Please read the included [chado/INSTALL.Chado.md](./chado/INSTALL.Chado.md) document for instructions on how to install the Chado schema. +## Docker + +Chado has been dockerized with Flyway so that you can look around, and test migrations easily. +The following instructions are going to show you how to pull the already build images. If you would like to build your own image locally, there are instructins for that at the very bottom. + ### Using the Chado Docker Image -#### Locally Build the Docker Image -To build the docker image using the default values, run the following command: -```bash -docker build --tag gmod/chado:local --file docker/Dockerfile ./ -``` -If you would like to build a docker that uses a specific version of PostgreSQL then you can run the following command instead. In this case you will replace `` with the version of PostgreSQL. We currently support 12, 13, 14, 15, and 16. -```bash -docker build --tag gmod/chado:local --file docker/Dockerfile --build-arg PGSQL_VERSION= ./ -``` -#### Using the Chado Docker -You can start and work within the Chado container by using the following command. +You can start and work within the Chado container by using the following commands. You will want to replace the `` with a current version available on Github. You can see the available options [on the github package repository](https://github.com/GMOD/Chado/pkgs/container/chado). + ```bash -docker run -it gmod/chado:local +docker run -it ghcr.io/gmod/chado: ``` -This will start the PostgreSQL server and give you access to a bash terminal within the docker container. +If you don't have the image locally, this will pull it down from the Github package repository first and then start a container for you. PostgreSQL and flyway will be running within the container and Chado will be cloned in the current working directory. + +The container will be shut down once you exit the opened bash terminal. If you want the container to remain running then you would use `-dit` instead of `-it` to run docker in detached mode. As a test, you can run the `flyway info` command after starting the container: @@ -114,14 +112,17 @@ psql -U postgres -h localhost -d chado ``` You will be prompted for a password. The default password is `chadotest` -##### Testing a Pull Request -When you build the image as shown above, it actually uses the current code in your Chado clone. +### Testing a Pull Request + In order to allow you to modify the migrations while running the container, you will mount your current directory inside the container using the following approach. This way you can edit the files locally and they will be automatically updated within the container and available to flyway. + ```bash -docker build --tag gmod/chado:local --file docker/Dockerfile \ - --build-arg PGSQL_VERSION= ./ -docker run -it -rm --volume=$(pwd):/Chado gmod/chado:local +git clone https://github.com/GMOD/Chado chado-pr +cd chado-pr +git checkout +docker run -it -rm --volume=$(pwd):/Chado ghcr.io/gmod/chado:pr- ``` + You can test FlyWay migrations by running these flyway commands: - See what migrations need to be applied: @@ -138,7 +139,19 @@ You can test FlyWay migrations by running these flyway commands: The migrations have been applied correctly if you do not see any red errors. However, it is good practice to run `flyway info` again to confirm. +### Locally Build the Docker Image + +*The following commands should be carried out in a cloned version of this repository, in the root directory.* + +To build the docker image using the default values, run the following command: +```bash +docker build --tag gmod/chado:local --file docker/Dockerfile ./ +``` +If you would like to build a docker that uses a specific version of PostgreSQL then you can run the following command instead. In this case you will replace `` with the version of PostgreSQL. We currently support 12, 13, 14, 15, and 16. +```bash +docker build --tag gmod/chado:local --file docker/Dockerfile --build-arg PGSQL_VERSION= ./ +``` ## Chado Support From 6403faa9c93b4d74d238917168820595eed5a699 Mon Sep 17 00:00:00 2001 From: Lacey-Anne Sanderson Date: Thu, 2 May 2024 12:22:37 -0600 Subject: [PATCH 15/20] Create MAIN-buildDocker.yml --- .github/workflows/MAIN-buildDocker.yml | 62 ++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 .github/workflows/MAIN-buildDocker.yml diff --git a/.github/workflows/MAIN-buildDocker.yml b/.github/workflows/MAIN-buildDocker.yml new file mode 100644 index 00000000..875e777e --- /dev/null +++ b/.github/workflows/MAIN-buildDocker.yml @@ -0,0 +1,62 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +# GitHub recommends pinning actions to a commit SHA. +# To get a newer version, you will need to update the SHA. +# You can also reference a tag or branch, but the action may change without warning. + +name: Publish Docker image +on: + push: + branches: + - '1.4' + - '142-github-workflows-to-help-with-review' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + push_to_registry: + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + id-token: write + attestations: write + + steps: + - name: Check out the repo + uses: actions/checkout@v4 + - name: Make Image Name all lowercase + run: | + echo "IMAGE_NAME=${IMAGE_NAME,,}" >>${GITHUB_ENV} + + - name: Log in to Docker Hub + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + id: push + uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 + with: + context: . + push: true + build-args: | + PGSQL_VERSION=16 + APPLY_MIGRATIONS=1 + file: 'docker/Dockerfile' + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:1.4 + labels: ${{ steps.meta.outputs.labels }} From 562950b99b58a22e0ca3f6ca1f437d4229d7bc73 Mon Sep 17 00:00:00 2001 From: Lacey Sanderson Date: Thu, 2 May 2024 12:46:13 -0600 Subject: [PATCH 16/20] Add arguement to apply migrations in build process. --- docker/Dockerfile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docker/Dockerfile b/docker/Dockerfile index 524d1bb5..2551877a 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -2,6 +2,7 @@ FROM ubuntu:24.04 ARG CHADO_VERSION='1.31' ARG PGSQL_VERSION='16' +ARG APPLY_MIGRATIONS=0 RUN apt-get update @@ -38,6 +39,12 @@ RUN cp flyway.toml /root/flyway.toml \ && chmod +x /usr/bin/entrypoint.sh \ && cp motd /etc/motd +RUN /etc/init.d/postgresql start \ + && flyway baseline \ + && if [ "$APPLY_MIGRATIONS" > "1" ] ; then \ + flyway migrate; \ + fi + WORKDIR /Chado RUN echo '[ ! -z "$TERM" -a -r /etc/motd ] && cat /etc/issue && cat /etc/motd' >> /etc/bash.bashrc From eef902cd67d6aad1120ae881d2610b5f800239d1 Mon Sep 17 00:00:00 2001 From: Lacey Sanderson Date: Thu, 2 May 2024 12:46:54 -0600 Subject: [PATCH 17/20] Remove makefile. --- docker/makefile | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 docker/makefile diff --git a/docker/makefile b/docker/makefile deleted file mode 100644 index dd819e3c..00000000 --- a/docker/makefile +++ /dev/null @@ -1,8 +0,0 @@ -all: v1.31 - -v1.31: - docker build \ - -t gmod/chado:1.31 \ - --build-arg CHADO_BRANCH=1.31-release \ - --build-arg CHADO_VERSION=1.31 \ - . From e4aa75c048dd6defe2e37529d4d0c532c60d0853 Mon Sep 17 00:00:00 2001 From: Lacey-Anne Sanderson Date: Thu, 2 May 2024 13:05:46 -0600 Subject: [PATCH 18/20] We need to give time for the db to startup --- docker/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/Dockerfile b/docker/Dockerfile index 2551877a..a44d17bc 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -40,6 +40,7 @@ RUN cp flyway.toml /root/flyway.toml \ && cp motd /etc/motd RUN /etc/init.d/postgresql start \ + && sleep 30 \ && flyway baseline \ && if [ "$APPLY_MIGRATIONS" > "1" ] ; then \ flyway migrate; \ From ba3396a31e1a9bdc50e37f8cc6451a5a0923be27 Mon Sep 17 00:00:00 2001 From: Lacey-Anne Sanderson Date: Thu, 2 May 2024 13:28:20 -0600 Subject: [PATCH 19/20] ensure string comparison works as expected. --- docker/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index a44d17bc..bf4cfc66 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -2,7 +2,7 @@ FROM ubuntu:24.04 ARG CHADO_VERSION='1.31' ARG PGSQL_VERSION='16' -ARG APPLY_MIGRATIONS=0 +ARG APPLY_MIGRATIONS='0' RUN apt-get update @@ -42,7 +42,7 @@ RUN cp flyway.toml /root/flyway.toml \ RUN /etc/init.d/postgresql start \ && sleep 30 \ && flyway baseline \ - && if [ "$APPLY_MIGRATIONS" > "1" ] ; then \ + && if [ "$APPLY_MIGRATIONS" = "1" ] ; then \ flyway migrate; \ fi From 11c6c77dd0162f9fede6ad022ec50a1b665f407f Mon Sep 17 00:00:00 2001 From: Lacey-Anne Sanderson Date: Thu, 2 May 2024 14:57:55 -0600 Subject: [PATCH 20/20] Give time to sleep ;-p --- .github/workflows/ALL-testMigrate.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ALL-testMigrate.yml b/.github/workflows/ALL-testMigrate.yml index 687ff5a2..f572edcb 100644 --- a/.github/workflows/ALL-testMigrate.yml +++ b/.github/workflows/ALL-testMigrate.yml @@ -27,11 +27,12 @@ jobs: run: | docker build --tag gmod/chado:local \ --file docker/Dockerfile \ - --build-arg PGSQL_VERSION="${{ matrix.pgsql-version }}" ./ + --build-arg PGSQL_VERSION="${{ matrix.pgsql-version }}" \ + --build-arg APPLY_MIGRATIONS=0 ./ # Just spin up docker the good ol' fashion way # then run flyway baseline and migrate. - - name: Run Flyway Baseline then migrate + - name: Run Flyway Migrate run: | docker run --name=chadodocker -tid gmod/chado:local - docker exec chadodocker flyway baseline + sleep 30 docker exec chadodocker flyway migrate