diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 95bd014..601d1ab 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,16 +18,19 @@ jobs: run: > ./mvnw clean install - name: Upload the artifact - if: github.ref == 'refs/heads/main' + if: github.ref == 'refs/heads/add_docker_publish' uses: actions/upload-artifact@v2 with: name: query-executor + path: target/cohort-requester*.jar sonar: runs-on: ubuntu-20.04 steps: - name: Checkout github repo uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Set up JDK 17 uses: actions/setup-java@v1 with: @@ -43,3 +46,54 @@ jobs: -Dsonar.projectKey=aphp_Cohort360-QueryExecutor env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + + publish: + if: github.ref == 'refs/heads/add_docker_publish' + needs: build + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + distribution: 'adopt' + java-version: '11' + + - name: Extract version from pom.xml + id: extract_version + run: | + VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) + echo "VERSION=$VERSION" >> $GITHUB_ENV + + - name: Download artifacts + uses: actions/download-artifact@v3 + with: + name: query-executor + path: target + + - name: Fetch pg dependency + run: | + POSTGRES_VERSION=$(mvn help:evaluate -Dexpression=postgres.version -q -DforceStdout) + mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.1:get -Dartifact=org.postgresql:postgresql:$POSTGRES_VERSION + mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.1:copy -Dartifact=org.postgresql:postgresql:$POSTGRES_VERSION -DoutputDirectory=./ + mv postgresql-$POSTGRES_VERSION.jar postgresql.jar + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + file: ./Dockerfile + push: true + tags: "aphpid/cohort360-queryexecutor:${{ env.VERSION }}" \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 5d31e87..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Publish Docker Image - -on: - workflow_run: - workflows: [ "build" ] - types: - - completed - -jobs: - build-and-publish: - if: github.ref == 'refs/heads/main' - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up JDK 11 - uses: actions/setup-java@v3 - with: - distribution: 'adopt' - java-version: '11' - - - name: Extract version from pom.xml - id: extract_version - run: | - VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) - echo "VERSION=$VERSION" >> $GITHUB_ENV - - - name: Download artifact - uses: actions/download-artifact@v3 - with: - name: query-executor - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Login to DockerHub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Build and push Docker image - uses: docker/build-push-action@v4 - with: - file: ./Dockerfile - push: true - tags: "${{ secrets.DOCKER_USERNAME }}/c360-query-executor:${{ env.VERSION }}" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 58e2d6a..e48d3de 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM harbor.eds.aphp.fr/cohort360/openjdk:11 +FROM eclipse-temurin:11 RUN useradd -m -s /bin/bash -u 185 spark USER spark