diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 9eca977..50ca6d1 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -1,8 +1,8 @@ name: Run tests on: - push: - branches: [ master ] + pull_request: + branches: [ main ] jobs: build: diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..636aa65 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,126 @@ +stages: + - test + - package + - deploy + +variables: + WS_ARTIFACT_PATH: target/eva-submission-ws-$ENVIRONMENT_NAME.war + MAVEN_SETTINGS: maven-settings.xml + URL_MAVEN_SETTINGS: https://api.github.com/repos/EBIvariation/configuration/contents/eva-maven-settings.xml + MEDIA_TYPE: application/vnd.github.raw + +test: + stage: test + image: maven:3.6.1-jdk-8-alpine + script: + - mvn test + environment: + name: test-env + only: + - master + - tags + +# Not executed, parent job definition for package +.package: + stage: package + image: maven:3.6.1-jdk-8-alpine + environment: + name: $ENVIRONMENT_NAME + before_script: + - DATETIME=$(date +%Y-%m-%dT%H-%M-%S) + - apk add --update curl + - curl -u $GITHUB_USER:$GITHUB_TOKEN -H "Accept:$MEDIA_TYPE" $URL_MAVEN_SETTINGS > $MAVEN_SETTINGS + script: + - mvn package --settings $MAVEN_SETTINGS -P $MAVEN_PROFILE -DskipTests + - cp target/eva-submission-ws*.war.original $WS_ARTIFACT_PATH + after_script: + - rm $MAVEN_SETTINGS + artifacts: + paths: + - $WS_ARTIFACT_PATH + +package-internal: + extends: .package + variables: + ENVIRONMENT_NAME: internal + MAVEN_PROFILE: internal + only: + - master + +package-development: + extends: .package + variables: + ENVIRONMENT_NAME: development + MAVEN_PROFILE: development + only: + - master + +package-production: + extends: .package + variables: + ENVIRONMENT_NAME: production + # Use production_processing to use production rather than public database + MAVEN_PROFILE: production_processing + only: + - tags + +# Not executed, parent job definition for deployments +.deploy-tomcat: + stage: deploy + image: alpine:3.9.5 + environment: + name: $ENVIRONMENT_NAME + script: + - DATETIME=$(date +%Y-%m-%dT%H-%M-%S) + - apk add --update curl + - curl -u $TOMCAT_USER:$TOMCAT_PASSWORD -T "$WS_ARTIFACT_PATH" "http://$TOMCAT_HOST/manager/text/deploy?update=true&path=/eva/webservices/submission-ws&version=$DATETIME" | grep "OK - Deployed application" + +deploy-tomcat-internal: + extends: .deploy-tomcat + variables: + ENVIRONMENT_NAME: internal + TOMCAT_USER: $TOMCAT_INTERNAL_USER + TOMCAT_PASSWORD: $TOMCAT_INTERNAL_PASSWORD + TOMCAT_HOST: $TOMCAT_INTERNAL_HOST + dependencies: + - package-internal + only: + - master + +deploy-tomcat-development: + extends: .deploy-tomcat + variables: + ENVIRONMENT_NAME: development + TOMCAT_USER: $TOMCAT_DEVELOPMENT_USER + TOMCAT_PASSWORD: $TOMCAT_DEVELOPMENT_PASSWORD + TOMCAT_HOST: $TOMCAT_DEVELOPMENT_HOST + dependencies: + - package-development + only: + - master + +deploy-tomcat-production: + extends: .deploy-tomcat + when: manual + variables: + ENVIRONMENT_NAME: production + TOMCAT_USER: $TOMCAT_PRODUCTION_USER + TOMCAT_PASSWORD: $TOMCAT_PRODUCTION_PASSWORD + TOMCAT_HOST: $TOMCAT_PRODUCTION_HOST + dependencies: + - package-production + only: + - tags + +deploy-tomcat-production-fallback: + extends: .deploy-tomcat + when: manual + variables: + ENVIRONMENT_NAME: production + TOMCAT_USER: $TOMCAT_PRODUCTION_FALLBACK_USER + TOMCAT_PASSWORD: $TOMCAT_PRODUCTION_FALLBACK_PASSWORD + TOMCAT_HOST: $TOMCAT_PRODUCTION_FALLBACK_HOST + dependencies: + - package-production + only: + - tags diff --git a/src/main/java/uk/ac/ebi/eva/submission/model/Submission.java b/src/main/java/uk/ac/ebi/eva/submission/model/Submission.java index 70ce798..3fb161d 100644 --- a/src/main/java/uk/ac/ebi/eva/submission/model/Submission.java +++ b/src/main/java/uk/ac/ebi/eva/submission/model/Submission.java @@ -12,7 +12,7 @@ import java.util.Objects; @Entity -@Table(name = "submission") +@Table(schema = "eva_submissions", name = "submission") public class Submission { public Submission() { diff --git a/src/main/java/uk/ac/ebi/eva/submission/model/SubmissionAccount.java b/src/main/java/uk/ac/ebi/eva/submission/model/SubmissionAccount.java index 0e9c066..53c7127 100644 --- a/src/main/java/uk/ac/ebi/eva/submission/model/SubmissionAccount.java +++ b/src/main/java/uk/ac/ebi/eva/submission/model/SubmissionAccount.java @@ -12,8 +12,10 @@ import java.util.List; @Entity -@Table(name = "submission_account", uniqueConstraints = {@UniqueConstraint(columnNames = {"user_id", "login_type"})}) +@Table(schema = "eva_submissions", name = "submission_account", uniqueConstraints = {@UniqueConstraint(columnNames = + {"user_id", "login_type"})}) public class SubmissionAccount { + @Id private String id; diff --git a/src/main/java/uk/ac/ebi/eva/submission/model/SubmissionDetails.java b/src/main/java/uk/ac/ebi/eva/submission/model/SubmissionDetails.java index 0f014c4..7321fee 100644 --- a/src/main/java/uk/ac/ebi/eva/submission/model/SubmissionDetails.java +++ b/src/main/java/uk/ac/ebi/eva/submission/model/SubmissionDetails.java @@ -8,8 +8,9 @@ import javax.persistence.Table; @Entity -@Table(name = "submission_details") +@Table(schema = "eva_submissions", name = "submission_details") public class SubmissionDetails { + @Id @Column(name = "submission_id") private String submissionId; @@ -28,7 +29,7 @@ public SubmissionDetails() { } - public SubmissionDetails(Submission submission){ + public SubmissionDetails(Submission submission) { this.submission = submission; } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 051a10c..1801dca 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -3,6 +3,7 @@ spring.datasource.url=|eva.evapro.jdbc.url| spring.datasource.username=|eva.evapro.user| spring.datasource.password=|eva.evapro.password| spring.jpa.hibernate.ddl-auto=update +spring.jpa.properties.hibernate.default_schema=eva_submissions spring.jmx.default-domain=eva.ebi.ac.uk.submission-ws.|timestamp| globus.clientId=|globus.client-id| diff --git a/src/test/java/uk/ac/ebi/eva/submission/integration/SubmissionWSIntegrationTest.java b/src/test/java/uk/ac/ebi/eva/submission/integration/SubmissionWSIntegrationTest.java index 1ecfc6c..80151b6 100644 --- a/src/test/java/uk/ac/ebi/eva/submission/integration/SubmissionWSIntegrationTest.java +++ b/src/test/java/uk/ac/ebi/eva/submission/integration/SubmissionWSIntegrationTest.java @@ -69,7 +69,8 @@ public class SubmissionWSIntegrationTest { private GlobusDirectoryProvisioner globusDirectoryProvisioner; @Container - static PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer<>("postgres:9.6"); + static PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer<>("postgres:9.6") + .withInitScript("init.sql"); @DynamicPropertySource static void dataSourceProperties(DynamicPropertyRegistry registry) { diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index 9406208..3165af0 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -1,3 +1,5 @@ +spring.jpa.properties.hibernate.default_schema=eva_submissions + globus.clientId= globus.clientSecret= globus.refreshToken= diff --git a/src/test/resources/init.sql b/src/test/resources/init.sql new file mode 100644 index 0000000..48b9389 --- /dev/null +++ b/src/test/resources/init.sql @@ -0,0 +1 @@ +CREATE SCHEMA IF NOT EXISTS eva_submissions; \ No newline at end of file