diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 85d374815..9c7376bc7 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -16,6 +16,11 @@ on: description: 'Build environment' required: true type: string + release_version: + description: 'Release version' + required: true + type: string + default: '' jobs: cleanup: @@ -36,6 +41,8 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 + with: + ref: ${{ inputs.release_version || github.ref }} - name: Update environment variables for .env env: @@ -73,5 +80,10 @@ jobs: - name: Build and bring up containers without cache working-directory: ./marketplace-build run: | - docker compose build --no-cache --build-arg BUILD_ENV=${{ inputs.build_env }} + if [ -n "${{ inputs.release_version }}" ]; then + BUILD_VERSION=${{ inputs.release_version }} + else + BUILD_VERSION=$(xml sel -t -v "//_:project/_:version" ../marketplace-service/pom.xml) + fi + docker compose build --no-cache --build-arg BUILD_ENV=${{ inputs.build_env }} --build-arg BUILD_VERSION=$BUILD_VERSION docker compose up --force-recreate -d diff --git a/.github/workflows/docker-release.yml b/.github/workflows/release-build.yml similarity index 62% rename from .github/workflows/docker-release.yml rename to .github/workflows/release-build.yml index 77549bf99..a3ae5a7e8 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/release-build.yml @@ -1,12 +1,12 @@ -name: Docker Release +name: Release Build on: push: branches: [ "master" ] workflow_dispatch: inputs: - image_version: - description: 'Marketplace Docker image version' + release_version: + description: 'Release version' required: true default: 'latest' build_env: @@ -19,11 +19,40 @@ env: SERVICE_IMAGE_NAME: marketplace-service jobs: + tagging_source: + name: Create new GH Tag for release + runs-on: self-hosted + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Update version + if: ${{ inputs.release_version != '' }} + env: + POM_FILE: './marketplace-service/pom.xml' + PACKAGE_FILE: './marketplace-ui/package.json' + run: | + xml ed -L -u "//_:project/_:version" -v "${{ inputs.release_version }}" $POM_FILE + sed -i 's/"version": "[^"]*"/"version": "${{ inputs.release_version }}"/' $PACKAGE_FILE + + - name: Create release tag + continue-on-error: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + git fetch --tags + git push origin :refs/tags/${{ inputs.release_version }} + git tag -d ${{ inputs.release_version }} + git tag -a ${{ inputs.release_version }} -m "Released ${{ inputs.release_version }} by ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" + git push origin ${{ inputs.release_version }} build: name: Build Docker images + needs: tagging_source uses: ./.github/workflows/docker-build.yml with: + release_version: ${{ inputs.release_version }} build_env: ${{ inputs.build_env }} release: @@ -58,7 +87,7 @@ jobs: - name: Refine release version run: | # This strips the git ref prefix from the version. - VERSION=${{ github.event.inputs.image_version }} + VERSION=${{ github.event.inputs.release_version }} # This uses the Docker `latest` tag convention. [ "$VERSION" == "main" ] && VERSION=latest echo "VERSION=$VERSION" >> $GITHUB_ENV diff --git a/marketplace-build/docker-compose.yml b/marketplace-build/docker-compose.yml index 5ba3d718d..4b61cc430 100644 --- a/marketplace-build/docker-compose.yml +++ b/marketplace-build/docker-compose.yml @@ -51,6 +51,8 @@ services: build: context: ../marketplace-service dockerfile: Dockerfile + args: + - BUILD_VERSION=${BUILD_VERSION} ports: - "8080:8080" depends_on: diff --git a/marketplace-service/Dockerfile b/marketplace-service/Dockerfile index 8a963d725..95f00a3c3 100644 --- a/marketplace-service/Dockerfile +++ b/marketplace-service/Dockerfile @@ -11,7 +11,8 @@ WORKDIR /app RUN rm -rf /usr/local/tomcat/webapps/ROOT # Copy the WAR file to the webapps directory in Tomcat -COPY --from=build-api /app/target/marketplace-service-0.0.1-SNAPSHOT.war /usr/local/tomcat/webapps/marketplace-service.war +ARG BUILD_VERSION +COPY --from=build-api /app/target/marketplace-service-${BUILD_VERSION}.war /usr/local/tomcat/webapps/marketplace-service.war # Expose port 8080 EXPOSE 8080