diff --git a/.gitignore b/.gitignore index 7b1ad1ba..5d82761e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ +.gradle */.gradle */build/ */!gradle/wrapper/gradle-wrapper.jar +*.class .idea *.iws @@ -9,4 +11,16 @@ #pattern for excluding generated proto files from git **/api/messages/ -**/api/events/ \ No newline at end of file +**/api/events/ + +# Docker volumes +artifactory/volume/ + +# Auto-generated +.project +.classpath +org.eclipse.buildship.core.prefs + +# Other +api-gateway-service/bin/main/application.yml +eureka-service-discovery/bin/main/application.yml \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..5a329c87 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,16 @@ +services: + - docker + +env: + # Update if building docker-compose-services.yml breaks + - ARTIFACTORY_IP=172.17.0.1 + +before_install: + - docker-compose -f docker-compose-storage.yml up -d + # Deploy expected configuration to Artifactory + - docker-compose -f docker-compose-storage.yml run --rm api-deployer bash -c 'while ! /setup.sh | grep successfully; do echo "Still waiting..."; sleep 1; done' + +script: + - docker-compose -f docker-compose.yml -f docker-compose-services.yml pull + - docker-compose -f docker-compose-storage.yml run --rm api-deployer /api-deployer.sh + - docker-compose -f docker-compose.yml -f docker-compose-services.yml build \ No newline at end of file diff --git a/accounting-service/Dockerfile b/accounting-service/Dockerfile index 2b805da1..6bdaf7ee 100644 --- a/accounting-service/Dockerfile +++ b/accounting-service/Dockerfile @@ -1,4 +1,24 @@ +FROM gradle:5.4.1 AS builder + +ARG ARTIFACTORY_URL +ARG ARTIFACTORY_USER +ARG ARTIFACTORY_PASSWORD +ARG ARTIFACTORY_REPO + +ENV ORG_GRADLE_PROJECT_artifactoryUrl=${ARTIFACTORY_URL} +ENV ORG_GRADLE_PROJECT_artifactoryRepo=${ARTIFACTORY_REPO} +ENV ORG_GRADLE_PROJECT_artifactoryUser=${ARTIFACTORY_USER} +# Enforce more security +ENV ORG_GRADLE_PROJECT_artifactoryPassword=${ARTIFACTORY_PASSWORD} + +WORKDIR /project + +COPY . /project + +RUN gradle :accounting-app:build + FROM openjdk:8-jre-alpine -COPY ./accounting-app/build/libs/accounting-service-app-0.1-SNAPSHOT.jar /accounting-service-app-0.1-SNAPSHOT.jar +COPY --from=builder /project/accounting-app/build/libs/accounting-service-app-0.1-SNAPSHOT.jar /accounting-service-app-0.1-SNAPSHOT.jar + EXPOSE 8093 ENTRYPOINT ["java", "-jar", "accounting-service-app-0.1-SNAPSHOT.jar", "--spring.profiles.active=docker"] diff --git a/accounting-service/accounting-api/build.gradle b/accounting-service/accounting-api/build.gradle index 74a948d6..b80ff037 100644 --- a/accounting-service/accounting-api/build.gradle +++ b/accounting-service/accounting-api/build.gradle @@ -1,17 +1,10 @@ -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.4.RELEASE") - } +plugins { + id "com.jfrog.artifactory" version "4.9.8" + id 'maven-publish' + id 'idea' + id 'io.spring.dependency-management' } - -apply plugin: 'java' -apply plugin: 'idea' -apply plugin: 'io.spring.dependency-management' - group 'com.microservices.accounting.api' version = apiVersion @@ -19,11 +12,6 @@ jar { archiveBaseName = "accounting-api" } -repositories { - mavenLocal() - mavenCentral() -} - dependencies { compile 'org.springframework.cloud:spring-cloud-openfeign-core' compile 'javax.validation:validation-api:2.0.1.Final' @@ -42,3 +30,38 @@ uploadArchives { mavenLocal() } } + +publishing { + publications { + mavenJava(MavenPublication) { + artifactId "${project.name}" + groupId = group + version = project.version + from components.java + } + } +} + +artifactory { + contextUrl = "${artifactoryUrl}" //The base Artifactory URL if not overridden by the publisher/resolver + publish { + repository { + repoKey = "${artifactoryRepo}" + username = "${artifactoryUser}" + password = "${artifactoryPassword}" + maven = true + } + defaults { + publications('mavenJava') + publishArtifacts = true + } + } + resolve { + repository { + repoKey = "${artifactoryRepo}" + username = "${artifactoryUser}" + password = "${artifactoryPassword}" + maven = true + } + } +} \ No newline at end of file diff --git a/accounting-service/accounting-app/build.gradle b/accounting-service/accounting-app/build.gradle index 2f7045d5..a766f8be 100644 --- a/accounting-service/accounting-app/build.gradle +++ b/accounting-service/accounting-app/build.gradle @@ -1,13 +1,3 @@ -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.1.4.RELEASE' - } -} - -apply plugin: 'java' apply plugin: 'idea' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' @@ -20,11 +10,6 @@ bootJar { sourceCompatibility = 1.8 -repositories { - mavenLocal() - mavenCentral() -} - dependencies { compile "com.microservices.accounting.api:accounting-api:${accountingApiVersion}" compile 'org.springframework.boot:spring-boot-starter-web' diff --git a/accounting-service/build.gradle b/accounting-service/build.gradle index e69de29b..03782b89 100644 --- a/accounting-service/build.gradle +++ b/accounting-service/build.gradle @@ -0,0 +1,21 @@ +plugins { + id 'java' + id "org.springframework.boot" version "2.1.4.RELEASE" +} + +allprojects { + repositories { + maven { + url "${artifactoryUrl}/${artifactoryRepo}" // The Artifactory (preferably virtual) repository to resolve from + credentials { // Optional resolver credentials (leave out to use anonymous resolution) + username = "${artifactoryUser}" // Artifactory user name + password = "${artifactoryPassword}" // Password or API Key + } + } + } + apply plugin: "java" + dependencies { + //Check for the latest version here: http://plugins.gradle.org/plugin/com.jfrog.artifactory + implementation "org.jfrog.buildinfo:build-info-extractor-gradle:4+" + } +} diff --git a/api-deployer/Dockerfile b/api-deployer/Dockerfile new file mode 100644 index 00000000..e57ebe5c --- /dev/null +++ b/api-deployer/Dockerfile @@ -0,0 +1,13 @@ +FROM gradle:5.4.1 + +COPY ./api-deployer.sh /api-deployer.sh +COPY ./config.yml /artifactory.yml +COPY ./repo-setup.sh /setup.sh + +RUN chmod +x /api-deployer.sh /setup.sh + +RUN apt-get update && apt-get install -y vim + +VOLUME [ "/project" ] + +WORKDIR /project diff --git a/api-deployer/api-deployer.sh b/api-deployer/api-deployer.sh new file mode 100644 index 00000000..9afab948 --- /dev/null +++ b/api-deployer/api-deployer.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +set -e +set -x + +API_PROJECTS=" + laundry-management-service/laundrymanagement-api + order-management-service/ordermanagement-api + taskcoordinator/taskcoordinator-api + tariff-management-service/tariffmanagement-api + accounting-service/accounting-api + user-management-service/usermanagement-api +" + +WORKDIR="${PWD}" +TMPDIR="$(mktemp -d)" + +echo "Copy project into ${TMPDIR}..." 1>&2 +cp -r "${WORKDIR}/." "${TMPDIR}" + +cd "${TMPDIR}" + +for project in ${API_PROJECTS}; do + cd "${project}" + gradle build + gradle artifactoryPublish + cd "${TMPDIR}" +done + +cd "${WORKDIR}" + +rm -rf "${TMPDIR}" \ No newline at end of file diff --git a/api-deployer/config.yml b/api-deployer/config.yml new file mode 100644 index 00000000..5c29e934 --- /dev/null +++ b/api-deployer/config.yml @@ -0,0 +1,354 @@ + +localRepositories: + "artifactory-build-info": + type: buildinfo + description: "Build Info repository" + includesPattern: "**/*" + repoLayout: "simple-default" + dockerApiVersion: V2 + forceNugetAuthentication: false + blackedOut: false + handleReleases: true + handleSnapshots: true + maxUniqueSnapshots: 0 + maxUniqueTags: 0 + suppressPomConsistencyChecks: true + propertySets: + archiveBrowsingEnabled: false + snapshotVersionBehavior: unique + checksumPolicyType: "client-checksums" + calculateYumMetadata: false + yumRootDepth: 0 + debianTrivialLayout: false + enableFileListsIndexing: false + + artifacts: + type: gradle + includesPattern: "**/*" + repoLayout: "gradle-default" + dockerApiVersion: V2 + forceNugetAuthentication: false + blackedOut: false + handleReleases: true + handleSnapshots: true + maxUniqueSnapshots: 0 + maxUniqueTags: 0 + suppressPomConsistencyChecks: true + propertySets: + archiveBrowsingEnabled: false + snapshotVersionBehavior: unique + checksumPolicyType: "client-checksums" + calculateYumMetadata: false + yumRootDepth: 0 + debianTrivialLayout: false + enableFileListsIndexing: false + + "gradle-dev-local": + type: gradle + includesPattern: "**/*" + repoLayout: "gradle-default" + dockerApiVersion: V2 + forceNugetAuthentication: false + blackedOut: false + handleReleases: true + handleSnapshots: true + maxUniqueSnapshots: 0 + maxUniqueTags: 0 + suppressPomConsistencyChecks: true + propertySets: + archiveBrowsingEnabled: false + snapshotVersionBehavior: unique + checksumPolicyType: "client-checksums" + calculateYumMetadata: false + yumRootDepth: 0 + debianTrivialLayout: false + enableFileListsIndexing: false + + "gradle-release-local": + type: gradle + includesPattern: "**/*" + repoLayout: "gradle-default" + dockerApiVersion: V2 + forceNugetAuthentication: false + blackedOut: false + handleReleases: true + handleSnapshots: true + maxUniqueSnapshots: 0 + maxUniqueTags: 0 + suppressPomConsistencyChecks: true + propertySets: + archiveBrowsingEnabled: false + snapshotVersionBehavior: unique + checksumPolicyType: "client-checksums" + calculateYumMetadata: false + yumRootDepth: 0 + debianTrivialLayout: false + enableFileListsIndexing: false + + "libs-release-local": + type: maven + includesPattern: "**/*" + repoLayout: "maven-2-default" + dockerApiVersion: V2 + forceNugetAuthentication: false + blackedOut: false + handleReleases: true + handleSnapshots: false + maxUniqueSnapshots: 0 + maxUniqueTags: 0 + suppressPomConsistencyChecks: false + propertySets: + archiveBrowsingEnabled: false + snapshotVersionBehavior: unique + checksumPolicyType: "client-checksums" + calculateYumMetadata: false + yumRootDepth: 0 + debianTrivialLayout: false + enableFileListsIndexing: false + + "libs-snapshot-local": + type: maven + includesPattern: "**/*" + repoLayout: "maven-2-default" + dockerApiVersion: V2 + forceNugetAuthentication: false + blackedOut: false + handleReleases: false + handleSnapshots: true + maxUniqueSnapshots: 0 + maxUniqueTags: 0 + suppressPomConsistencyChecks: false + propertySets: + archiveBrowsingEnabled: false + snapshotVersionBehavior: unique + checksumPolicyType: "client-checksums" + calculateYumMetadata: false + yumRootDepth: 0 + debianTrivialLayout: false + enableFileListsIndexing: false + +remoteRepositories: + "gradle-plugins": + type: gradle + includesPattern: "**/*" + repoLayout: "gradle-default" + dockerApiVersion: V2 + forceNugetAuthentication: false + blackedOut: false + handleReleases: true + handleSnapshots: true + maxUniqueSnapshots: 0 + maxUniqueTags: 0 + suppressPomConsistencyChecks: true + propertySets: + archiveBrowsingEnabled: false + url: "https://plugins.gradle.org/m2/" + offline: false + hardFail: false + storeArtifactsLocally: true + fetchJarsEagerly: false + fetchSourcesEagerly: false + retrievalCachePeriodSecs: 600 + assumedOfflinePeriodSecs: 300 + missedRetrievalCachePeriodSecs: 1800 + remoteRepoChecksumPolicyType: "generate-if-absent" + unusedArtifactsCleanupPeriodHours: 0 + shareConfiguration: false + synchronizeProperties: false + listRemoteFolderItems: true + rejectInvalidJars: false + p2OriginalUrl: "https://plugins.gradle.org/m2/" + contentSynchronisation: + enabled: false + blockMismatchingMimeTypes: true + mismatchingMimeTypesOverrideList: "" + bypassHeadRequests: false + allowAnyHostAuth: false + socketTimeoutMillis: 100000 + enableCookieManagement: false + enableTokenAuthentication: false + propagateQueryParams: false + + jcenter: + type: maven + includesPattern: "**/*" + repoLayout: "maven-2-default" + dockerApiVersion: V2 + forceNugetAuthentication: false + blackedOut: false + handleReleases: true + handleSnapshots: true + maxUniqueSnapshots: 0 + maxUniqueTags: 0 + suppressPomConsistencyChecks: false + propertySets: + archiveBrowsingEnabled: false + url: "https://jcenter.bintray.com" + offline: false + hardFail: false + storeArtifactsLocally: true + fetchJarsEagerly: false + fetchSourcesEagerly: false + retrievalCachePeriodSecs: 600 + assumedOfflinePeriodSecs: 300 + missedRetrievalCachePeriodSecs: 1800 + remoteRepoChecksumPolicyType: "generate-if-absent" + unusedArtifactsCleanupPeriodHours: 0 + shareConfiguration: false + synchronizeProperties: false + listRemoteFolderItems: true + rejectInvalidJars: false + p2OriginalUrl: "https://jcenter.bintray.com" + contentSynchronisation: + enabled: false + blockMismatchingMimeTypes: true + mismatchingMimeTypesOverrideList: "" + bypassHeadRequests: false + allowAnyHostAuth: false + socketTimeoutMillis: 100000 + enableCookieManagement: false + enableTokenAuthentication: false + propagateQueryParams: false + + "maven-central": + type: maven + includesPattern: "**/*" + repoLayout: "maven-2-default" + dockerApiVersion: V2 + forceNugetAuthentication: false + blackedOut: false + handleReleases: true + handleSnapshots: true + maxUniqueSnapshots: 0 + maxUniqueTags: 0 + suppressPomConsistencyChecks: false + propertySets: + archiveBrowsingEnabled: false + url: "https://repo1.maven.org/maven2/" + offline: false + hardFail: false + storeArtifactsLocally: true + fetchJarsEagerly: false + fetchSourcesEagerly: false + retrievalCachePeriodSecs: 600 + assumedOfflinePeriodSecs: 300 + missedRetrievalCachePeriodSecs: 1800 + remoteRepoChecksumPolicyType: "generate-if-absent" + unusedArtifactsCleanupPeriodHours: 0 + shareConfiguration: false + synchronizeProperties: false + listRemoteFolderItems: true + rejectInvalidJars: false + p2OriginalUrl: "https://repo1.maven.org/maven2/" + contentSynchronisation: + enabled: false + blockMismatchingMimeTypes: true + mismatchingMimeTypesOverrideList: "" + bypassHeadRequests: false + allowAnyHostAuth: false + socketTimeoutMillis: 100000 + enableCookieManagement: false + enableTokenAuthentication: false + propagateQueryParams: false + +virtualRepositories: + "gradle-dev": + type: gradle + includesPattern: "**/*" + repoLayout: "gradle-default" + dockerApiVersion: V2 + forceNugetAuthentication: false + artifactoryRequestsCanRetrieveRemoteArtifacts: false + resolveDockerTagsByTimestamp: false + repositories: + - "gradle-dev-local" + - jcenter + pomRepositoryReferencesCleanupPolicy: discard_active_reference + defaultDeploymentRepo: "gradle-dev-local" + virtualCacheConfig: + virtualRetrievalCachePeriodSecs: 600 + forceMavenAuthentication: false + debianDefaultArchitectures: "i386,amd64" + + "gradle-release": + type: gradle + includesPattern: "**/*" + repoLayout: "gradle-default" + dockerApiVersion: V2 + forceNugetAuthentication: false + artifactoryRequestsCanRetrieveRemoteArtifacts: false + resolveDockerTagsByTimestamp: false + repositories: + - "gradle-release-local" + - jcenter + pomRepositoryReferencesCleanupPolicy: discard_active_reference + defaultDeploymentRepo: "gradle-release-local" + virtualCacheConfig: + virtualRetrievalCachePeriodSecs: 600 + forceMavenAuthentication: false + debianDefaultArchitectures: "i386,amd64" + + "libs-release": + type: maven + includesPattern: "**/*" + repoLayout: "maven-2-default" + dockerApiVersion: V2 + forceNugetAuthentication: false + artifactoryRequestsCanRetrieveRemoteArtifacts: false + resolveDockerTagsByTimestamp: false + repositories: + - "libs-release-local" + - jcenter + pomRepositoryReferencesCleanupPolicy: discard_active_reference + defaultDeploymentRepo: "libs-release-local" + virtualCacheConfig: + virtualRetrievalCachePeriodSecs: 600 + forceMavenAuthentication: false + debianDefaultArchitectures: "i386,amd64" + + "libs-snapshot": + type: maven + includesPattern: "**/*" + repoLayout: "maven-2-default" + dockerApiVersion: V2 + forceNugetAuthentication: false + artifactoryRequestsCanRetrieveRemoteArtifacts: false + resolveDockerTagsByTimestamp: false + repositories: + - "libs-snapshot-local" + - jcenter + pomRepositoryReferencesCleanupPolicy: discard_active_reference + defaultDeploymentRepo: "libs-snapshot-local" + virtualCacheConfig: + virtualRetrievalCachePeriodSecs: 600 + forceMavenAuthentication: false + debianDefaultArchitectures: "i386,amd64" + + repo: + type: gradle + includesPattern: "**/*" + repoLayout: "gradle-default" + dockerApiVersion: V2 + forceNugetAuthentication: false + artifactoryRequestsCanRetrieveRemoteArtifacts: false + resolveDockerTagsByTimestamp: false + repositories: + - artifacts + - "gradle-dev-local" + - "gradle-release-local" + - "libs-release-local" + - "libs-snapshot-local" + - "gradle-plugins" + - jcenter + - "maven-central" + - "gradle-dev" + - "gradle-release" + - "libs-release" + - "libs-snapshot" + pomRepositoryReferencesCleanupPolicy: discard_active_reference + defaultDeploymentRepo: artifacts + virtualCacheConfig: + virtualRetrievalCachePeriodSecs: 600 + forceMavenAuthentication: false + debianDefaultArchitectures: "i386,amd64" + diff --git a/api-deployer/repo-setup.sh b/api-deployer/repo-setup.sh new file mode 100644 index 00000000..e3566bfd --- /dev/null +++ b/api-deployer/repo-setup.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +curl --user "${ORG_GRADLE_PROJECT_artifactoryUser}:${ORG_GRADLE_PROJECT_artifactoryPassword}" \ + --request PATCH \ + --header "Content-Type:application/yaml" \ + --upload-file /artifactory.yml \ + "${ORG_GRADLE_PROJECT_artifactoryUrl}/api/system/configuration" diff --git a/api-gateway-service/build.gradle b/api-gateway-service/build.gradle index 6bf6b652..52efed87 100644 --- a/api-gateway-service/build.gradle +++ b/api-gateway-service/build.gradle @@ -1,7 +1,4 @@ buildscript { - repositories { - mavenCentral() - } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.4.RELEASE") } @@ -20,11 +17,6 @@ bootJar { sourceCompatibility = 1.8 -repositories { - mavenCentral() - mavenLocal() -} - dependencyManagement { imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:${releaseTrainVersion}" diff --git a/api-gateway-service/src/main/resources/application.yml b/api-gateway-service/src/main/resources/application.yml index 45a085b6..2533a180 100644 --- a/api-gateway-service/src/main/resources/application.yml +++ b/api-gateway-service/src/main/resources/application.yml @@ -5,7 +5,7 @@ spring: eureka: client: serviceUrl: - defaultZone: http://localhost:8761/eureka/ + defaultZone: http://eureka:8761/eureka/ zuul: routes: @@ -16,4 +16,4 @@ zuul: tariffs: path: /tariffs/** serviceId: tariff-management-service - strip-prefix: false \ No newline at end of file + strip-prefix: false diff --git a/artifactory/.dockerignore b/artifactory/.dockerignore new file mode 100644 index 00000000..4833bbb0 --- /dev/null +++ b/artifactory/.dockerignore @@ -0,0 +1 @@ +volume diff --git a/artifactory/Dockerfile b/artifactory/Dockerfile new file mode 100644 index 00000000..0acaea30 --- /dev/null +++ b/artifactory/Dockerfile @@ -0,0 +1,10 @@ +FROM docker.bintray.io/jfrog/artifactory-oss + +COPY ./entrypoint.sh /entrypoint.sh + +RUN [ "/busybox/ip", "r" ] + +ENTRYPOINT [ "/bin/bash", "/entrypoint.sh" ] + +# Required for chown +USER "root" diff --git a/artifactory/entrypoint.sh b/artifactory/entrypoint.sh new file mode 100644 index 00000000..4c64e7b5 --- /dev/null +++ b/artifactory/entrypoint.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +# XXX: Fix up permissions on volume in Windows(Hyper-V) and Linux +chown -R artifactory:artifactory /var/opt/jfrog/artifactory + +# Return from root under expected user +exec su artifactory /entrypoint-artifactory.sh diff --git a/doc/Docker.md b/doc/Docker.md new file mode 100644 index 00000000..8d691bb9 --- /dev/null +++ b/doc/Docker.md @@ -0,0 +1,59 @@ +# Bulding and deploying in Docker + +## Dependency caching and publishing + +Many of services, presented in this repository, +have an API package which is a dependency for other services. +Originally, resolving this dependency meant bulding the package, deploying it into local Maven +and then referencing to local Maven in other services. +Unfortunatelly, in order to build the software in a predictable environment, +this method has been abandoned. +That's because local Maven can be supported in Docker only by using a volume +but it is expected that each service is built as a separate Docker image. +Thus, since at built time, feature of volumes is unavailable in Docker, +there has to be an external repository to do the job. + +After a little research, Artifactory project has been choosen to resolve issue with publishing of API artifacts. +Also, Artifactory provides two features that seems quite useful: ability to proxy remote repositories, +including caching of requested data, and feature of virtual repositories that represent set of repositories as one. + +Thus, to build this project, it is required to raise Artifactory service in Docker first: +``` +docker-compose -f docker-compose-storage.yml up +``` + +Then, after Artifactory is up, it is necessary to deploy first-time configuration by calling: +``` +docker-compose -f docker-compose-storage.yml run --rm api-deployer /setup.sh +``` + +If previous command has succeeded, then it is time to build API artifacts and deploy them into the Artifactory: +``` +docker-compose -f docker-compose-storage.yml run --rm api-deployer /api-deployer.sh +``` + +## Building services + +After API artifacts is available at Artifactory, it is time to build all the images: +``` +docker-compose -f docker-compose.yml -f docker-compose-services.yml pull +docker-compose -f docker-compose.yml -f docker-compose-services.yml build +``` + +It is also possible to skip this step as `docker-compose` automatically builds images the first time +but after changes has been made, it is necessary to call the `build` command again. + +## Deploying services + +``` +docker-compose -f docker-compose.yml -f docker-compose-services.yml up +``` + +## Including new service + +If a new service is in development, first it is necessary to rely on Artifactory +in order to resolve all the dependencies. Examples of such repository configuration can be found in existing services. +To deploy API of a service, one must edit `api-deployer/api-deployer.sh` and include path to API in proper order in this script. +To build a Docker image, one can rely on examples of `Dockerfile` in other services. + +Also, it is important to remember that referencing `localhost` inside of Docker container means only reference to the current container itself and not the host nor any other container. Thus, working with external services, they must be referenced by service name in `docker-compose.yml` files. \ No newline at end of file diff --git a/docker-compose-services.yml b/docker-compose-services.yml index 2424bdee..9f6eba74 100644 --- a/docker-compose-services.yml +++ b/docker-compose-services.yml @@ -1,26 +1,51 @@ -version: '3' +version: '3.4' + +x-artifactory-args: &artifactory-args + ARTIFACTORY_URL: "http://${ARTIFACTORY_IP:-172.24.0.1}:8081/artifactory" + ARTIFACTORY_USER: "admin" + ARTIFACTORY_PASSWORD: "password" + ARTIFACTORY_REPO: "repo" + services: accounting: - build: ./accounting-service + build: + context: ./accounting-service + args: + <<: *artifactory-args ports: - "8093:8093" laundry-management: - build: ./laundry-management-service + build: + context: ./laundry-management-service + args: + <<: *artifactory-args ports: - "8089:8089" order-management: - build: ./order-management-service + build: + context: ./order-management-service + args: + <<: *artifactory-args ports: - "8091:8091" tariff-management: - build: ./tariff-management-service + build: + context: ./tariff-management-service + args: + <<: *artifactory-args ports: - "8092:8092" taskcoordinator: - build: ./taskcoordinator + build: + context: ./taskcoordinator + args: + <<: *artifactory-args ports: - "8095:8095" user-management: - build: ./user-management-service + build: + context: ./user-management-service + args: + <<: *artifactory-args ports: - "8094:8094" \ No newline at end of file diff --git a/docker-compose-storage.yml b/docker-compose-storage.yml new file mode 100644 index 00000000..f1f69a10 --- /dev/null +++ b/docker-compose-storage.yml @@ -0,0 +1,24 @@ +version: "3" + +services: + artifactory: + build: ./artifactory + # Login user: admin, password: password + image: artifactory-oss + # entrypoint: /bin/bash -c 'while true; do sleep 1; done' + ports: + - "8081:8081" + volumes: + - "./artifactory/volume:/var/opt/jfrog/artifactory" + + api-deployer: + build: ./api-deployer + image: api-deployer + working_dir: "/project" + volumes: + - ".:/project" + environment: + ORG_GRADLE_PROJECT_artifactoryUrl: "http://artifactory:8081/artifactory" + ORG_GRADLE_PROJECT_artifactoryUser: admin + ORG_GRADLE_PROJECT_artifactoryPassword: password + ORG_GRADLE_PROJECT_artifactoryRepo: "repo" diff --git a/docker-compose.yml b/docker-compose.yml index 3b19d1ed..43d0ea32 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '2' +version: '3.4' services: zookeeper: image: wurstmeister/zookeeper @@ -27,7 +27,7 @@ services: ports: - "9411:9411" eureka: - image: eureka-server + image: springcloud/eureka ports: - "8761:8761" postgres: diff --git a/eureka-service-discovery/build.gradle b/eureka-service-discovery/build.gradle index 75195f9c..40e12201 100644 --- a/eureka-service-discovery/build.gradle +++ b/eureka-service-discovery/build.gradle @@ -10,10 +10,6 @@ group = 'com.microservices' version = applicationVersion sourceCompatibility = '1.8' -repositories { - mavenCentral() -} - ext { set('springCloudVersion', "Greenwich.SR2") } diff --git a/grafana/docker-build/dockerfile b/grafana/docker-build/dockerfile index 58c7b77f..5e3ab446 100644 --- a/grafana/docker-build/dockerfile +++ b/grafana/docker-build/dockerfile @@ -1,4 +1,4 @@ -FROM grafana/grafana +FROM grafana/grafana:6.3.6 COPY ./entrypoint.sh /entrypoint.sh @@ -9,5 +9,7 @@ RUN \ && apt-get -y install gettext-base \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* + +RUN chmod a+x /entrypoint.sh -ENTRYPOINT [ "/entrypoint.sh" ] \ No newline at end of file +ENTRYPOINT [ "/entrypoint.sh" ] diff --git a/grafana/provisioning/dashboards/tc-dashboard/order-metrics.json b/grafana/provisioning/dashboards/tc-dashboard/order-metrics.json index c3b9d5d9..a62c334f 100644 --- a/grafana/provisioning/dashboards/tc-dashboard/order-metrics.json +++ b/grafana/provisioning/dashboards/tc-dashboard/order-metrics.json @@ -742,8 +742,8 @@ "list": [ { "current": { - "text": "20s", - "value": "20s" + "text": "10s", + "value": "10s" }, "hide": 2, "label": null, @@ -751,11 +751,11 @@ "options": [ { "selected": true, - "text": "20s", - "value": "20s" + "text": "10s", + "value": "10s" } ], - "query": "20s", + "query": "10s", "skipUrlSync": false, "type": "constant" }, diff --git a/grafana/provisioning/dashboards/tc-dashboard/tc-dashboard.json b/grafana/provisioning/dashboards/tc-dashboard/tc-dashboard.json index 6a237045..202d0a85 100644 --- a/grafana/provisioning/dashboards/tc-dashboard/tc-dashboard.json +++ b/grafana/provisioning/dashboards/tc-dashboard/tc-dashboard.json @@ -333,7 +333,7 @@ "type": "sum" } ], - "query": "name:jvm_gc_memory_* AND instance:$instance", + "query": "name:jvm_gc_memory_* AND instance.keyword:$instance", "refId": "A", "timeField": "@timestamp" } @@ -1630,8 +1630,8 @@ }, { "current": { - "text": "20s", - "value": "20s" + "text": "10s", + "value": "10s" }, "hide": 2, "label": null, @@ -1639,11 +1639,11 @@ "options": [ { "selected": true, - "text": "20s", - "value": "20s" + "text": "10s", + "value": "10s" } ], - "query": "20s", + "query": "10s", "skipUrlSync": false, "type": "constant" } diff --git a/grafana/provisioning/datasources/elastic.yml b/grafana/provisioning/datasources/elastic.yml index f417a3de..d818cbd1 100644 --- a/grafana/provisioning/datasources/elastic.yml +++ b/grafana/provisioning/datasources/elastic.yml @@ -7,9 +7,9 @@ datasources: access: direct # Index name database: ${index.name} - url: http://localhost:9200 + url: http://elasticsearch:9200 jsonData: # Field used as time timeField: "@timestamp" # Elasticsearch version (as number, without dot) - esVersion: 70 \ No newline at end of file + esVersion: 70 diff --git a/laundry-management-service/Dockerfile b/laundry-management-service/Dockerfile index ca1368ce..cfa41f16 100644 --- a/laundry-management-service/Dockerfile +++ b/laundry-management-service/Dockerfile @@ -1,4 +1,23 @@ +FROM gradle:5.4.1 AS builder + +ARG ARTIFACTORY_URL +ARG ARTIFACTORY_USER +ARG ARTIFACTORY_PASSWORD +ARG ARTIFACTORY_REPO + +ENV ORG_GRADLE_PROJECT_artifactoryUrl=${ARTIFACTORY_URL} +ENV ORG_GRADLE_PROJECT_artifactoryRepo=${ARTIFACTORY_REPO} +ENV ORG_GRADLE_PROJECT_artifactoryUser=${ARTIFACTORY_USER} +# Enforce more security +ENV ORG_GRADLE_PROJECT_artifactoryPassword=${ARTIFACTORY_PASSWORD} + +WORKDIR /project + +COPY . /project + +RUN gradle :laundrymanagement-app:build + FROM openjdk:8-jre-alpine -COPY ./laundrymanagement-app/build/libs/laundry-management-service-app-0.1-SNAPSHOT.jar /laundry-management-service-app-0.1-SNAPSHOT.jar +COPY --from=builder /project/laundrymanagement-app/build/libs/laundry-management-service-app-0.1-SNAPSHOT.jar /laundry-management-service-app-0.1-SNAPSHOT.jar EXPOSE 8089 ENTRYPOINT ["java", "-jar", "laundry-management-service-app-0.1-SNAPSHOT.jar", "--spring.profiles.active=docker"] diff --git a/laundry-management-service/build.gradle b/laundry-management-service/build.gradle index e69de29b..03782b89 100644 --- a/laundry-management-service/build.gradle +++ b/laundry-management-service/build.gradle @@ -0,0 +1,21 @@ +plugins { + id 'java' + id "org.springframework.boot" version "2.1.4.RELEASE" +} + +allprojects { + repositories { + maven { + url "${artifactoryUrl}/${artifactoryRepo}" // The Artifactory (preferably virtual) repository to resolve from + credentials { // Optional resolver credentials (leave out to use anonymous resolution) + username = "${artifactoryUser}" // Artifactory user name + password = "${artifactoryPassword}" // Password or API Key + } + } + } + apply plugin: "java" + dependencies { + //Check for the latest version here: http://plugins.gradle.org/plugin/com.jfrog.artifactory + implementation "org.jfrog.buildinfo:build-info-extractor-gradle:4+" + } +} diff --git a/laundry-management-service/laundrymanagement-api/build.gradle b/laundry-management-service/laundrymanagement-api/build.gradle index 731f8842..54b2482e 100644 --- a/laundry-management-service/laundrymanagement-api/build.gradle +++ b/laundry-management-service/laundrymanagement-api/build.gradle @@ -1,10 +1,7 @@ plugins { - id 'java' id 'com.google.protobuf' version '0.8.8' -} - -repositories { - mavenCentral() + id "com.jfrog.artifactory" version "4.9.8" + id 'maven-publish' } group = 'com.microservices.laundrymanagement' @@ -38,4 +35,39 @@ uploadArchives { repositories { mavenLocal() } +} + +publishing { + publications { + mavenJava(MavenPublication) { + artifactId "${project.name}" + groupId = group + version = project.version + from components.java + } + } +} + +artifactory { + contextUrl = "${artifactoryUrl}" //The base Artifactory URL if not overridden by the publisher/resolver + publish { + repository { + repoKey = "${artifactoryRepo}" + username = "${artifactoryUser}" + password = "${artifactoryPassword}" + maven = true + } + defaults { + publications('mavenJava') + publishArtifacts = true + } + } + resolve { + repository { + repoKey = "${artifactoryRepo}" + username = "${artifactoryUser}" + password = "${artifactoryPassword}" + maven = true + } + } } \ No newline at end of file diff --git a/laundry-management-service/laundrymanagement-app/build.gradle b/laundry-management-service/laundrymanagement-app/build.gradle index 8bbf99c7..3dd09d0c 100644 --- a/laundry-management-service/laundrymanagement-app/build.gradle +++ b/laundry-management-service/laundrymanagement-app/build.gradle @@ -1,14 +1,3 @@ -buildscript { - // these repositories and dependencies are used by Gradle itself - repositories { - mavenCentral() - } - dependencies { - classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.1.4.RELEASE' - } -} - -apply plugin: 'java' apply plugin: 'idea' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' @@ -21,12 +10,6 @@ bootJar { sourceCompatibility = 1.8 -// these repositories are used in project -repositories { - mavenCentral() - mavenLocal() -} - dependencyManagement { imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:${releaseTrainVersion}" diff --git a/order-management-service/Dockerfile b/order-management-service/Dockerfile index 4d1db769..6b368647 100644 --- a/order-management-service/Dockerfile +++ b/order-management-service/Dockerfile @@ -1,4 +1,23 @@ +FROM gradle:5.4.1 AS builder + +ARG ARTIFACTORY_URL +ARG ARTIFACTORY_USER +ARG ARTIFACTORY_PASSWORD +ARG ARTIFACTORY_REPO + +ENV ORG_GRADLE_PROJECT_artifactoryUrl=${ARTIFACTORY_URL} +ENV ORG_GRADLE_PROJECT_artifactoryRepo=${ARTIFACTORY_REPO} +ENV ORG_GRADLE_PROJECT_artifactoryUser=${ARTIFACTORY_USER} +# Enforce more security +ENV ORG_GRADLE_PROJECT_artifactoryPassword=${ARTIFACTORY_PASSWORD} + +WORKDIR /project + +COPY . /project + +RUN gradle -Dorg.gradle.daemon=false :ordermanagement-app:build + FROM openjdk:8-jre-alpine -COPY ./ordermanagement-app/build/libs/order-management-service-app-0.1-SNAPSHOT.jar /order-management-service-app-0.1-SNAPSHOT.jar +COPY --from=builder /project/ordermanagement-app/build/libs/order-management-service-app-0.1-SNAPSHOT.jar /order-management-service-app-0.1-SNAPSHOT.jar EXPOSE 8091 ENTRYPOINT ["java", "-jar", "order-management-service-app-0.1-SNAPSHOT.jar", "--spring.profiles.active=docker"] diff --git a/order-management-service/build.gradle b/order-management-service/build.gradle index e69de29b..03782b89 100644 --- a/order-management-service/build.gradle +++ b/order-management-service/build.gradle @@ -0,0 +1,21 @@ +plugins { + id 'java' + id "org.springframework.boot" version "2.1.4.RELEASE" +} + +allprojects { + repositories { + maven { + url "${artifactoryUrl}/${artifactoryRepo}" // The Artifactory (preferably virtual) repository to resolve from + credentials { // Optional resolver credentials (leave out to use anonymous resolution) + username = "${artifactoryUser}" // Artifactory user name + password = "${artifactoryPassword}" // Password or API Key + } + } + } + apply plugin: "java" + dependencies { + //Check for the latest version here: http://plugins.gradle.org/plugin/com.jfrog.artifactory + implementation "org.jfrog.buildinfo:build-info-extractor-gradle:4+" + } +} diff --git a/order-management-service/ordermanagement-api/build.gradle b/order-management-service/ordermanagement-api/build.gradle index 46b8893e..d98d8c9d 100644 --- a/order-management-service/ordermanagement-api/build.gradle +++ b/order-management-service/ordermanagement-api/build.gradle @@ -1,19 +1,9 @@ -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.4.RELEASE") - classpath("com.google.protobuf:protobuf-gradle-plugin:0.8.8") - } -} - -apply plugin: 'java' -apply plugin: 'com.google.protobuf' -apply plugin: 'io.spring.dependency-management' - -repositories { - mavenCentral() +plugins { + id 'java' + id 'com.google.protobuf' version '0.8.8' + id "com.jfrog.artifactory" version "4.9.8" + id "io.spring.dependency-management" + id 'maven-publish' } group = 'com.microservices.ordermanagement' @@ -58,4 +48,39 @@ uploadArchives { repositories { mavenLocal() } +} + +publishing { + publications { + mavenJava(MavenPublication) { + artifactId "${project.name}" + groupId = group + version = project.version + from components.java + } + } +} + +artifactory { + contextUrl = "${artifactoryUrl}" //The base Artifactory URL if not overridden by the publisher/resolver + publish { + repository { + repoKey = "${artifactoryRepo}" + username = "${artifactoryUser}" + password = "${artifactoryPassword}" + maven = true + } + defaults { + publications('mavenJava') + publishArtifacts = true + } + } + resolve { + repository { + repoKey = "${artifactoryRepo}" + username = "${artifactoryUser}" + password = "${artifactoryPassword}" + maven = true + } + } } \ No newline at end of file diff --git a/order-management-service/ordermanagement-app/build.gradle b/order-management-service/ordermanagement-app/build.gradle index 8116fa80..b5578246 100644 --- a/order-management-service/ordermanagement-app/build.gradle +++ b/order-management-service/ordermanagement-app/build.gradle @@ -1,12 +1,3 @@ -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.4.RELEASE") - } -} - apply plugin: 'java' apply plugin: 'idea' apply plugin: 'org.springframework.boot' @@ -20,11 +11,6 @@ bootJar { sourceCompatibility = 1.8 -repositories { - mavenCentral() - mavenLocal() -} - dependencyManagement { imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:${releaseTrainVersion}" @@ -36,7 +22,7 @@ dependencies { compile 'org.springframework.boot:spring-boot-starter-data-jpa' compile 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client' compile 'org.springframework.cloud:spring-cloud-starter-zipkin' - compile "com.microservices.ordermanagement.api:ordermanagement-api:${orderManagementApiVersion}" + compile "com.microservices.ordermanagement:ordermanagement-api:${orderManagementApiVersion}" compile "com.microservices.laundrymanagement:laundrymanagement-api:${laundryManagementApiVersion}" compile 'com.google.protobuf:protobuf-java:3.8.0' compile 'org.flywaydb:flyway-core:5.2.4' diff --git a/rest-assured-tests/build.gradle b/rest-assured-tests/build.gradle index 44550571..fe3095fa 100644 --- a/rest-assured-tests/build.gradle +++ b/rest-assured-tests/build.gradle @@ -7,10 +7,6 @@ version '1.0-SNAPSHOT' sourceCompatibility = 1.8 -repositories { - mavenCentral() -} - dependencies { testCompile 'org.projectlombok:lombok:1.18.4' testCompile 'io.rest-assured:rest-assured:4.1.0' diff --git a/tariff-management-service/Dockerfile b/tariff-management-service/Dockerfile index c8c98f3d..44e63289 100644 --- a/tariff-management-service/Dockerfile +++ b/tariff-management-service/Dockerfile @@ -1,4 +1,23 @@ +FROM gradle:5.4.1 AS builder + +ARG ARTIFACTORY_URL +ARG ARTIFACTORY_USER +ARG ARTIFACTORY_PASSWORD +ARG ARTIFACTORY_REPO + +ENV ORG_GRADLE_PROJECT_artifactoryUrl=${ARTIFACTORY_URL} +ENV ORG_GRADLE_PROJECT_artifactoryRepo=${ARTIFACTORY_REPO} +ENV ORG_GRADLE_PROJECT_artifactoryUser=${ARTIFACTORY_USER} +# Enforce more security +ENV ORG_GRADLE_PROJECT_artifactoryPassword=${ARTIFACTORY_PASSWORD} + +WORKDIR /project + +COPY . /project + +RUN gradle :tariffmanagement-app:build + FROM openjdk:8-jre-alpine -COPY ./tariffmanagement-app/build/libs/tariff-management-service-app-0.1-SNAPSHOT.jar /tariff-management-service-app-0.1-SNAPSHOT.jar +COPY --from=builder /project/tariffmanagement-app/build/libs/tariff-management-service-app-0.1-SNAPSHOT.jar /tariff-management-service-app-0.1-SNAPSHOT.jar EXPOSE 8092 ENTRYPOINT ["java", "-jar", "tariff-management-service-app-0.1-SNAPSHOT.jar", "--spring.profiles.active=docker"] diff --git a/tariff-management-service/build.gradle b/tariff-management-service/build.gradle index e69de29b..02f7e42a 100644 --- a/tariff-management-service/build.gradle +++ b/tariff-management-service/build.gradle @@ -0,0 +1,22 @@ +plugins { + id 'java' + id "org.springframework.boot" version "2.1.4.RELEASE" +} + +allprojects { + repositories { + maven { + url "${artifactoryUrl}/${artifactoryRepo}" // The Artifactory (preferably virtual) repository to resolve from + credentials { // Optional resolver credentials (leave out to use anonymous resolution) + username = "${artifactoryUser}" // Artifactory user name + password = "${artifactoryPassword}" // Password or API Key + } + } + } + apply plugin: "java" + dependencies { + //Check for the latest version here: http://plugins.gradle.org/plugin/com.jfrog.artifactory + implementation "org.jfrog.buildinfo:build-info-extractor-gradle:4+" + } +} + diff --git a/tariff-management-service/tariffmanagement-api/build.gradle b/tariff-management-service/tariffmanagement-api/build.gradle index fa8809c5..a83590f2 100644 --- a/tariff-management-service/tariffmanagement-api/build.gradle +++ b/tariff-management-service/tariffmanagement-api/build.gradle @@ -1,25 +1,13 @@ -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.4.RELEASE") - } +plugins { + id 'io.spring.dependency-management' + id "com.jfrog.artifactory" version "4.9.8" + id 'maven-publish' + id 'idea' } - -apply plugin: 'java' -apply plugin: 'idea' -apply plugin: 'io.spring.dependency-management' - group 'com.microservices.tariffmanagement' version = apiVersion -repositories { - mavenLocal() - mavenCentral() -} - dependencies { compile 'org.springframework.cloud:spring-cloud-openfeign-core' compileOnly 'org.projectlombok:lombok:1.18.4' @@ -37,3 +25,38 @@ uploadArchives { mavenLocal() } } + +publishing { + publications { + mavenJava(MavenPublication) { + artifactId "${project.name}" + groupId = group + version = project.version + from components.java + } + } +} + +artifactory { + contextUrl = "${artifactoryUrl}" //The base Artifactory URL if not overridden by the publisher/resolver + publish { + repository { + repoKey = "${artifactoryRepo}" + username = "${artifactoryUser}" + password = "${artifactoryPassword}" + maven = true + } + defaults { + publications('mavenJava') + publishArtifacts = true + } + } + resolve { + repository { + repoKey = "${artifactoryRepo}" + username = "${artifactoryUser}" + password = "${artifactoryPassword}" + maven = true + } + } +} diff --git a/tariff-management-service/tariffmanagement-app/build.gradle b/tariff-management-service/tariffmanagement-app/build.gradle index befd5abc..1742831a 100644 --- a/tariff-management-service/tariffmanagement-app/build.gradle +++ b/tariff-management-service/tariffmanagement-app/build.gradle @@ -1,13 +1,3 @@ -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.4.RELEASE") - } -} - -apply plugin: 'java' apply plugin: 'idea' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' @@ -20,11 +10,6 @@ bootJar { sourceCompatibility = 1.8 -repositories { - mavenLocal() - mavenCentral() -} - dependencyManagement { imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:${releaseTrainVersion}" diff --git a/tariff-management-service/tariffmanagement-app/src/main/resources/application-docker.properties b/tariff-management-service/tariffmanagement-app/src/main/resources/application-docker.properties index 0ca50665..b03d8148 100644 --- a/tariff-management-service/tariffmanagement-app/src/main/resources/application-docker.properties +++ b/tariff-management-service/tariffmanagement-app/src/main/resources/application-docker.properties @@ -1,2 +1,3 @@ # Database properties -spring.datasource.url=jdbc:postgresql://postgres:5432/laundry_db \ No newline at end of file +spring.datasource.url=jdbc:postgresql://postgres:5432/laundry_db +eureka.client.serviceUrl.defaultZone=http://eureka:8761/eureka/ diff --git a/taskcoordinator/Dockerfile b/taskcoordinator/Dockerfile index 44cf52a6..32c67278 100644 --- a/taskcoordinator/Dockerfile +++ b/taskcoordinator/Dockerfile @@ -1,5 +1,24 @@ +FROM gradle:5.4.1 AS builder + +ARG ARTIFACTORY_URL +ARG ARTIFACTORY_USER +ARG ARTIFACTORY_PASSWORD +ARG ARTIFACTORY_REPO + +ENV ORG_GRADLE_PROJECT_artifactoryUrl=${ARTIFACTORY_URL} +ENV ORG_GRADLE_PROJECT_artifactoryRepo=${ARTIFACTORY_REPO} +ENV ORG_GRADLE_PROJECT_artifactoryUser=${ARTIFACTORY_USER} +# Enforce more security +ENV ORG_GRADLE_PROJECT_artifactoryPassword=${ARTIFACTORY_PASSWORD} + +WORKDIR /project + +COPY . /project + +RUN gradle -Dorg.gradle.daemon=false -x test :taskcoordinator-app:build + FROM openjdk:8-jre-alpine -COPY ./taskcoordinator-app/build/libs/taskcoordinator-app-0.1-SNAPSHOT.jar /taskcoordinator-app-0.1-SNAPSHOT.jar +COPY --from=builder /project/taskcoordinator-app/build/libs/taskcoordinator-app-0.1-SNAPSHOT.jar /taskcoordinator-app-0.1-SNAPSHOT.jar EXPOSE 8095 # Hostname is a command in a docker container that returns the container id. # In order to enable subshell substitution, shell form is used diff --git a/taskcoordinator/build.gradle b/taskcoordinator/build.gradle index 8b137891..4f83baa2 100644 --- a/taskcoordinator/build.gradle +++ b/taskcoordinator/build.gradle @@ -1 +1,21 @@ +plugins { + id 'java' + id "org.springframework.boot" version "2.1.4.RELEASE" +} +allprojects { + repositories { + maven { + url "${artifactoryUrl}/${artifactoryRepo}" // The Artifactory (preferably virtual) repository to resolve from + credentials { // Optional resolver credentials (leave out to use anonymous resolution) + username = "${artifactoryUser}" // Artifactory user name + password = "${artifactoryPassword}" // Password or API Key + } + } + } + apply plugin: "java" + dependencies { + //Check for the latest version here: http://plugins.gradle.org/plugin/com.jfrog.artifactory + implementation "org.jfrog.buildinfo:build-info-extractor-gradle:4+" + } +} \ No newline at end of file diff --git a/taskcoordinator/taskcoordinator-api/build.gradle b/taskcoordinator/taskcoordinator-api/build.gradle index 926b3cdb..008e67eb 100644 --- a/taskcoordinator/taskcoordinator-api/build.gradle +++ b/taskcoordinator/taskcoordinator-api/build.gradle @@ -1,10 +1,8 @@ plugins { id 'java' id 'com.google.protobuf' version '0.8.8' -} - -repositories { - mavenCentral() + id "com.jfrog.artifactory" version "4.9.8" + id 'maven-publish' } group = 'com.microservices.taskcoordinator' @@ -38,4 +36,39 @@ uploadArchives { repositories { mavenLocal() } +} + +publishing { + publications { + mavenJava(MavenPublication) { + artifactId "${project.name}" + groupId = group + version = project.version + from components.java + } + } +} + +artifactory { + contextUrl = "${artifactoryUrl}" //The base Artifactory URL if not overridden by the publisher/resolver + publish { + repository { + repoKey = "${artifactoryRepo}" + username = "${artifactoryUser}" + password = "${artifactoryPassword}" + maven = true + } + defaults { + publications('mavenJava') + publishArtifacts = true + } + } + resolve { + repository { + repoKey = "${artifactoryRepo}" + username = "${artifactoryUser}" + password = "${artifactoryPassword}" + maven = true + } + } } \ No newline at end of file diff --git a/taskcoordinator/taskcoordinator-app/build.gradle b/taskcoordinator/taskcoordinator-app/build.gradle index 35688864..40a3d635 100644 --- a/taskcoordinator/taskcoordinator-app/build.gradle +++ b/taskcoordinator/taskcoordinator-app/build.gradle @@ -1,12 +1,3 @@ -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.4.RELEASE") - } -} - apply plugin: 'java' apply plugin: 'idea' apply plugin: 'org.springframework.boot' @@ -20,11 +11,6 @@ bootJar { sourceCompatibility = 1.8 -repositories { - mavenCentral() - mavenLocal() -} - dependencyManagement { imports { mavenBom "org.springframework.cloud:spring-cloud-dependencies:${releaseTrainVersion}" diff --git a/user-management-service/Dockerfile b/user-management-service/Dockerfile index 892be4b7..363479e8 100644 --- a/user-management-service/Dockerfile +++ b/user-management-service/Dockerfile @@ -1,4 +1,23 @@ +FROM gradle:5.4.1 AS builder + +ARG ARTIFACTORY_URL +ARG ARTIFACTORY_USER +ARG ARTIFACTORY_PASSWORD +ARG ARTIFACTORY_REPO + +ENV ORG_GRADLE_PROJECT_artifactoryUrl=${ARTIFACTORY_URL} +ENV ORG_GRADLE_PROJECT_artifactoryRepo=${ARTIFACTORY_REPO} +ENV ORG_GRADLE_PROJECT_artifactoryUser=${ARTIFACTORY_USER} +# Enforce more security +ENV ORG_GRADLE_PROJECT_artifactoryPassword=${ARTIFACTORY_PASSWORD} + +WORKDIR /project + +COPY . /project + +RUN gradle -Dorg.gradle.daemon=false :usermanagement-app:build + FROM openjdk:8-jre-alpine -COPY ./usermanagement-app/build/libs/user-management-service-0.1-SNAPSHOT.jar /user-management-service-0.1-SNAPSHOT.jar +COPY --from=builder /project/usermanagement-app/build/libs/usermanagement-service-app-0.1-SNAPSHOT.jar /user-management-service-app-0.1-SNAPSHOT.jar EXPOSE 8094 -ENTRYPOINT ["java", "-jar", "user-management-service-0.1-SNAPSHOT.jar", "--spring.profiles.active=docker"] +ENTRYPOINT ["java", "-jar", "user-management-service-app-0.1-SNAPSHOT.jar", "--spring.profiles.active=docker"] diff --git a/user-management-service/build.gradle b/user-management-service/build.gradle index e69de29b..03782b89 100644 --- a/user-management-service/build.gradle +++ b/user-management-service/build.gradle @@ -0,0 +1,21 @@ +plugins { + id 'java' + id "org.springframework.boot" version "2.1.4.RELEASE" +} + +allprojects { + repositories { + maven { + url "${artifactoryUrl}/${artifactoryRepo}" // The Artifactory (preferably virtual) repository to resolve from + credentials { // Optional resolver credentials (leave out to use anonymous resolution) + username = "${artifactoryUser}" // Artifactory user name + password = "${artifactoryPassword}" // Password or API Key + } + } + } + apply plugin: "java" + dependencies { + //Check for the latest version here: http://plugins.gradle.org/plugin/com.jfrog.artifactory + implementation "org.jfrog.buildinfo:build-info-extractor-gradle:4+" + } +} diff --git a/user-management-service/usermanagement-api/build.gradle b/user-management-service/usermanagement-api/build.gradle index ad2cd92d..e34f94b9 100644 --- a/user-management-service/usermanagement-api/build.gradle +++ b/user-management-service/usermanagement-api/build.gradle @@ -1,28 +1,17 @@ -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.4.RELEASE") - } +plugins { + id "com.jfrog.artifactory" version "4.9.8" + id 'maven-publish' + id 'idea' + id 'io.spring.dependency-management' } - -apply plugin: 'java' -apply plugin: 'idea' -apply plugin: 'io.spring.dependency-management' - -group 'com.microservices.usermanagement.api' +group 'com.microservices.usermanagement' version = apiVersion jar { archiveBaseName = "usermanagement-api" } -repositories { - mavenCentral() -} - dependencies { compile 'org.springframework.cloud:spring-cloud-openfeign-core' compileOnly 'org.projectlombok:lombok:1.18.4' @@ -40,3 +29,38 @@ uploadArchives { mavenLocal() } } + +publishing { + publications { + mavenJava(MavenPublication) { + artifactId "${project.name}" + groupId = group + version = project.version + from components.java + } + } +} + +artifactory { + contextUrl = "${artifactoryUrl}" //The base Artifactory URL if not overridden by the publisher/resolver + publish { + repository { + repoKey = "${artifactoryRepo}" + username = "${artifactoryUser}" + password = "${artifactoryPassword}" + maven = true + } + defaults { + publications('mavenJava') + publishArtifacts = true + } + } + resolve { + repository { + repoKey = "${artifactoryRepo}" + username = "${artifactoryUser}" + password = "${artifactoryPassword}" + maven = true + } + } +} \ No newline at end of file diff --git a/user-management-service/usermanagement-app/build.gradle b/user-management-service/usermanagement-app/build.gradle index fd905a58..d99c81c1 100644 --- a/user-management-service/usermanagement-app/build.gradle +++ b/user-management-service/usermanagement-app/build.gradle @@ -1,32 +1,18 @@ -buildscript { - repositories { - mavenCentral() - } - dependencies { - classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.1.4.RELEASE' - } -} - apply plugin: 'java' apply plugin: 'idea' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' bootJar { - baseName = 'usermanagement-app' + baseName = 'usermanagement-service-app' version = applicationVersion enabled = true } sourceCompatibility = 1.8 -repositories { - mavenLocal() - mavenCentral() -} - dependencies { - compile "com.microservices.usermanagement.api:usermanagementapi:${userManagementApiVersion}" + compile "com.microservices.usermanagement:usermanagement-api:${userManagementApiVersion}" compile 'org.springframework.boot:spring-boot-starter-web' compile 'org.springframework.boot:spring-boot-starter-data-jpa' compile 'org.flywaydb:flyway-core:5.2.4'