diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..12cfa28 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,31 @@ +variables: + GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task + MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository" + +image: maven:3.9.6-eclipse-temurin-17 + +stages: + - build + - test + +cache: + key: "${CI_JOB_NAME}" + paths: + - .m2/repository/ + - target/ + +build: + stage: build + script: + - mvn clean compile + +test: + stage: test + script: + - mvn verify -Pall-tests + artifacts: + when: always + reports: + junit: + - target/surefire-reports/TEST-*.xml + - target/failsafe-reports/TEST-*.xml diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile new file mode 100644 index 0000000..eb553cb --- /dev/null +++ b/.gitpod.Dockerfile @@ -0,0 +1,7 @@ +FROM gitpod/workspace-full + +USER gitpod + +RUN bash -c ". /home/gitpod/.sdkman/bin/sdkman-init.sh && \ + sdk install java 17.0.9-tem && \ + sdk default java 17.0.9-tem" diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 0000000..0c92254 --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,24 @@ +# This configuration file was automatically generated by Gitpod. +# Please adjust to your needs (see https://www.gitpod.io/docs/config-gitpod-file) +# and commit this file to your remote git repository to share the goodness with others. + +image: + file: .gitpod.Dockerfile + +tasks: + - init: mvn package -DskipTests=false + +vscode: + extensions: + - redhat.java + - vscjava.vscode-java-debug + - vscjava.vscode-maven + +# Ports to expose on workspace startup +ports: + - port: 8080 + onOpen: open-preview + name: Calculator API + description: Calculator API init + visibility: private + protocol: http diff --git a/Dockerfile b/Dockerfile index fc66aa7..dde17fa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,4 @@ -FROM maven:3.8.4-jdk-11 -MAINTAINER ricardogarfe +FROM maven:3.9.6-eclipse-temurin-17 RUN adduser --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password jetty USER jetty diff --git a/README.md b/README.md index 79c6de2..c343456 100644 --- a/README.md +++ b/README.md @@ -120,21 +120,25 @@ Press Control-C to stop and remove the container. ### 3.3. Run docker-compose environment -Define a service to use repository Docker image: +Define a service to use repository Docker image and execute all tests: ```yaml version: '3.8' services: calculator: - build: . + build: + context: . + dockerfile: Dockerfile ports: - "8080:8080" + command: > + sh -c "mvn verify -Pall-tests" ``` -Run docker-compose environment: +Run all tests in docker-compose environment: ```console -$ docker-compse up +$ docker-compose up ``` Access the web app at http://localhost:8080/api/calculator/ping in browser. diff --git a/docker-compose.yml b/docker-compose.yml index 08a02cd..7ac327c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,10 @@ version: '3.8' services: calculator: - build: . + build: + context: . + dockerfile: Dockerfile ports: - "8080:8080" + command: > + sh -c "mvn verify -Pall-tests" diff --git a/pom.xml b/pom.xml index d0e740d..5ad7dcc 100644 --- a/pom.xml +++ b/pom.xml @@ -29,6 +29,7 @@ 3.3.2 3.2.0 2.22.2 + 2.22.2 0.8.7 @@ -40,6 +41,39 @@ false false + + + + org.eclipse.jetty + jetty-maven-plugin + ${jetty.maven.plugin.version} + + + /calculator + + 8079 + stop-jetty-for-it + 10 + + + + start-jetty + pre-integration-test + + start + + + + stop-jetty + post-integration-test + + stop + + + + + + dev @@ -53,6 +87,82 @@ false true + + + + org.eclipse.jetty + jetty-maven-plugin + ${jetty.maven.plugin.version} + + + /calculator + + 8079 + stop-jetty-for-it + 10 + + + + start-jetty + pre-integration-test + + start + + + + stop-jetty + post-integration-test + + stop + + + + + + + + + bdd-test-environment + + + bdd-test + + false + true + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-tests + + integration-test + verify + + + + ${failsafeArgLine} + + ${skip.integration.tests} + + **/ITCalculatorAPITest.java + + + + + + + @@ -188,26 +298,7 @@ /calculator - 8079 - stop-jetty-for-it - 10 - - - start-jetty - pre-integration-test - - start - - - - stop-jetty - post-integration-test - - stop - - - org.apache.maven.plugins @@ -236,7 +327,7 @@ org.apache.maven.plugins maven-failsafe-plugin - 2.22.2 + ${maven.failsafe.plugin.version}