diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 329aa5e4f..749591383 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -22,6 +22,9 @@ on: type: string default: '' +env: + BASE_WORKING_DIR: /home/axonivy/marketplace/work + jobs: cleanup: name: Clean up docker container and images @@ -30,9 +33,17 @@ jobs: steps: - name: Bring down and remove containers and images continue-on-error: true - working-directory: ./marketplace-build/dev + working-directory: ${{ env.BASE_WORKING_DIR }} + run: | + docker compose -f publish/docker-compose.yml down --rmi all + - name: Delete old sources code + continue-on-error: true run: | - docker compose down --rmi all + echo "Clean up workspaces ${{ env.BASE_WORKING_DIR }}" + rm -rf ./marketplace-ui/* + rm -rf ./marketplace-service/* + rm -rf ./publish/* + rm -rf ./config/* build-and-deploy: name: Build and bring up docker containers @@ -45,9 +56,24 @@ jobs: with: ref: ${{ inputs.release_version || github.ref }} + - name: Copy resources to working directory + run : | + echo "Copy marketplace-ui to ${{ env.BASE_WORKING_DIR }} directory" + cp -r marketplace-ui ${{ env.BASE_WORKING_DIR }}/marketplace-ui + + echo "Copy marketplace-service to ${{ env.BASE_WORKING_DIR }} directory" + cp -r marketplace-service ${{ env.BASE_WORKING_DIR }}/marketplace-service + + echo "Copy nginx configs to config directory" + mkdir -p ${{ env.BASE_WORKING_DIR }}/config/nginx && cp -r marketplace-build/config/nginx/dev/* ${{ env.BASE_WORKING_DIR }}/config/nginx + + echo "Copy compose configs to publish directory" + mkdir -p ${{ env.BASE_WORKING_DIR }}/publish && cp -r marketplace-build/.env ${{ env.BASE_WORKING_DIR }}/publish/.env + cp -r marketplace-build/docker-compose.yml ${{ env.BASE_WORKING_DIR }}/publish/docker-compose.yml + - name: Update environment variables for .env env: - ENV_FILE: './marketplace-build/dev/.env' + ENV_FILE: '${{ env.BASE_WORKING_DIR }}/publish/.env' ROOT_USERNAME: ${{ secrets.MONGODB_ROOT_USERNAME }} ROOT_PASSWORD: ${{ secrets.MONGODB_ROOT_PASSWORD }} SERVICE_USERNAME: ${{ secrets.SERVICE_USERNAME }} @@ -76,23 +102,24 @@ jobs: sed -i "s/^MARKET_JWT_SECRET_KEY=.*$/MARKET_JWT_SECRET_KEY=$MARKET_JWT_SECRET_KEY/" $ENV_FILE sed -i "s/^MARKET_CORS_ALLOWED_ORIGIN=.*$/MARKET_CORS_ALLOWED_ORIGIN=$MARKET_CORS_ALLOWED_ORIGIN/" $ENV_FILE - - name: Update version and tagging source + - name: Update version if: ${{ inputs.release_version != '' }} continue-on-error: true env: - POM_FILE: './marketplace-service/pom.xml' - PACKAGE_FILE: './marketplace-ui/package.json' + POM_FILE: '${{ env.BASE_WORKING_DIR }}/marketplace-service/pom.xml' + PACKAGE_FILE: '${{ env.BASE_WORKING_DIR }}/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: Build and bring up containers without cache - working-directory: ./marketplace-build/dev + working-directory: ${{ env.BASE_WORKING_DIR }}/publish run: | if [ -n "${{ inputs.release_version }}" ]; then BUILD_VERSION="${{ inputs.release_version }}" else - BUILD_VERSION=$(xml sel -t -v "//_:project/_:version" ../../marketplace-service/pom.xml) + chmod +r ../marketplace-service/pom.xml + BUILD_VERSION=$(xml sel -t -v "//_:project/_:version" ../marketplace-service/pom.xml) fi docker compose build --build-arg BUILD_ENV=${{ inputs.build_env }} --build-arg BUILD_VERSION=$BUILD_VERSION diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index 03980425d..c43996396 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -1,8 +1,6 @@ name: Release Build on: - push: - branches: [ "master" ] workflow_dispatch: inputs: release_version: diff --git a/marketplace-build/.env b/marketplace-build/.env index ed05498de..d1b4b7edb 100644 --- a/marketplace-build/.env +++ b/marketplace-build/.env @@ -1,9 +1,11 @@ -MONGODB_INITDB_ROOT_USERNAME= +BUILD_ENV=staging +BUILD_VERSION=1.0.0-SNAPSHOT +MONGODB_INITDB_ROOT_USERNAME=octopus MONGODB_INITDB_ROOT_PASSWORD= SERVICE_MONGODB_HOST=mongodb -SERVICE_MONGODB_USER= +SERVICE_MONGODB_USER=octopus SERVICE_MONGODB_PASSWORD= -SERVICE_MONGODB_DATABASE=marketplace +SERVICE_MONGODB_DATABASE=marketplace-dev MARKET_GITHUB_MARKET_BRANCH= MARKET_GITHUB_TOKEN= MARKET_GITHUB_OAUTH_APP_CLIENT_ID= diff --git a/marketplace-build/README.md b/marketplace-build/README.md index 921067346..e375b1d24 100644 --- a/marketplace-build/README.md +++ b/marketplace-build/README.md @@ -1,6 +1,13 @@ # Get starts with Marketplace build +### Create docker network +For the marketplace-ui, marketplace-service, and marketplace MongoDB to be able to connect to each other. They must be in a same network. +To create a docker network for the marketplace, please run: + +* ``docker network create marketplace-network`` + ### Set up MongoDB with authentication mode +#### Init a admin user for MongoDb volume * Navigate to ``marketplace-build/config/mongodb`` and execute the ``docker-compose -f non-authen-docker-compose.yml up -d`` to start MongoDB with non-auth mode and create a root admin user. * [Optional] Execute authentication test for the created user @@ -12,21 +19,18 @@ This command should return the ``OK`` code * Down the non-authen instance to start the main docker compose file by run ``docker-compose down`` -### Docker build for DEV environment -#### Start from scratch: -* Navigate to ``marketplace-build`` +#### Start MongoDB container -* Run ``docker-compose up -d --build`` to start a Marketplace DEV at the local +* Start the authen instance by run ``docker-compose -f authen-docker-compose.yml up -d`` to start mongodb -#### If you already have MongoDB on your local machine with public port `27017` -* Create a docker network to connect ui > service > mongodb by run ``docker network create marketplace-network`` +### Docker build for local environment +#### Update the MongoDB configuration for env +* Navigate to ``marketplace-build/dev`` and edit ``.env`` base on your mongo configuration * Navigate to ``marketplace-build/dev`` * Run ``docker-compose up -d --build`` to start a Marketplace DEV at the local -> In case you want to set up the MongoDB as a standalone compose. Please run `docker-compose -f authen-docker-compose.yml up -d` in ``marketplace-build/config/mongodb`` - ### Docker release To release a new version for marketplace images, please trigger the ``Docker Release`` actions. * This GH Actions will trigger the ``Docker build`` on the master branch. @@ -34,10 +38,5 @@ To release a new version for marketplace images, please trigger the ``Docker Rel * Deploy new image to packages. Please verify the result in the ``Package`` after the build is completed. -### Start Docker compose for PROD deployment +### Start Docker compose for PROD/SPRINT deployment * Navigate to ``marketplace-build/release`` run ``docker-compose up -d`` to clone the docker images from GitHub packages and start the website - -### Start Docker compose using SPRINT release version -* Navigate to ``marketplace-build/release`` run ``docker-compose -f sprint-compose.yml up`` to clone the docker images from GitHub packages and start the website - - diff --git a/marketplace-build/config/nginx/nginx.conf b/marketplace-build/config/nginx/release/nginx.conf similarity index 84% rename from marketplace-build/config/nginx/nginx.conf rename to marketplace-build/config/nginx/release/nginx.conf index 9881bfdbe..95fbda90f 100644 --- a/marketplace-build/config/nginx/nginx.conf +++ b/marketplace-build/config/nginx/release/nginx.conf @@ -1,3 +1,6 @@ +user www-data; +worker_processes auto; + events {} http { @@ -18,10 +21,12 @@ http { location /marketplace-service { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + # Start using for forwarded domain proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Proto $scheme; + # End using for forwarded domain proxy_set_header X-NginX-Proxy true; - proxy_pass http://service:8080/marketplace-service; + proxy_pass http://preview_service:8080/marketplace-service; proxy_ssl_session_reuse off; proxy_set_header Host $http_host; proxy_cache_bypass $http_upgrade; diff --git a/marketplace-build/dev/.env b/marketplace-build/dev/.env index 1a037765b..e9d068e53 100644 --- a/marketplace-build/dev/.env +++ b/marketplace-build/dev/.env @@ -1,3 +1,5 @@ +BUILD_ENV=staging +BUILD_VERSION=1.0.0-SNAPSHOT MONGODB_INITDB_ROOT_USERNAME=octopus MONGODB_INITDB_ROOT_PASSWORD= SERVICE_MONGODB_HOST=10.193.8.78 diff --git a/marketplace-build/dev/docker-compose.yml b/marketplace-build/dev/docker-compose.yml index f296326af..260fd1f6c 100644 --- a/marketplace-build/dev/docker-compose.yml +++ b/marketplace-build/dev/docker-compose.yml @@ -1,3 +1,4 @@ +# Used for the local environment name: marketplace services: @@ -5,8 +6,6 @@ services: container_name: marketplace-ui build: context: ../../marketplace-ui - additional_contexts: - assets: ../../marketplace-build/ dockerfile: Dockerfile args: - BUILD_ENV=${BUILD_ENV} @@ -16,8 +15,6 @@ services: - marketcache:/usr/share/nginx/html/market-cache ports: - "4200:80" - depends_on: - - service networks: - marketplace-network diff --git a/marketplace-build/docker-compose.yml b/marketplace-build/docker-compose.yml index da74c466f..4fc1e9f36 100644 --- a/marketplace-build/docker-compose.yml +++ b/marketplace-build/docker-compose.yml @@ -1,38 +1,20 @@ +# Use for DEV instance built by GH Actions name: marketplace services: - mongodb: - container_name: marketplace-mongodb - build: - context: ./config/mongodb - dockerfile: Dockerfile - restart: always - ports: - - "27017:27017" - environment: - MONGODB_INITDB_ROOT_USERNAME: ${MONGODB_INITDB_ROOT_USERNAME} - MONGODB_INITDB_ROOT_PASSWORD: ${MONGODB_INITDB_ROOT_PASSWORD} - volumes: - - mongodata:/data/db - - ./config/mongodb/mongod.conf:/etc/mongod.conf - ui: container_name: marketplace-ui build: context: ../marketplace-ui - additional_contexts: - assets: ../marketplace-build/ dockerfile: Dockerfile args: - BUILD_ENV=${BUILD_ENV} restart: always volumes: - - ./config/nginx/nginx.conf:/etc/nginx/nginx.conf + - ../config/nginx/nginx.conf:/etc/nginx/nginx.conf - marketcache:/usr/share/nginx/html/market-cache ports: - "4200:80" - depends_on: - - service service: container_name: marketplace-service @@ -59,8 +41,6 @@ services: - BUILD_VERSION=${BUILD_VERSION} ports: - "8080:8080" - depends_on: - - mongodb volumes: mongodata: diff --git a/marketplace-build/release/.env b/marketplace-build/release/.env index 9af06af38..d8dfb5f8a 100644 --- a/marketplace-build/release/.env +++ b/marketplace-build/release/.env @@ -1,3 +1,5 @@ +BUILD_ENV=staging +BUILD_VERSION=1.0.0-SNAPSHOT RELEASE_VERSION=sprint MONGODB_INITDB_ROOT_USERNAME=octopus MONGODB_INITDB_ROOT_PASSWORD= diff --git a/marketplace-build/release/docker-compose.yml b/marketplace-build/release/docker-compose.yml index ce0a71a01..f8fc73f25 100644 --- a/marketplace-build/release/docker-compose.yml +++ b/marketplace-build/release/docker-compose.yml @@ -1,21 +1,9 @@ -name: marketplace-release_${RELEASE_VERSION} +# Use for the release build instance (PREVIEW and PROD) +# The prefix 'preview_' used to detach dev and preview version on 1 docker system +name: marketplace-preview_${RELEASE_VERSION} services: - mongodb: - build: - context: ../config/mongodb - dockerfile: Dockerfile - restart: always - expose: - - 27017 - environment: - MONGODB_INITDB_ROOT_USERNAME: ${MONGODB_INITDB_ROOT_USERNAME} - MONGODB_INITDB_ROOT_PASSWORD: ${MONGODB_INITDB_ROOT_PASSWORD} - volumes: - - mongodata:/data/db - - ../config/mongodb/mongod.conf:/etc/mongod.conf - - ui: + preview_ui: image: ghcr.io/axonivy-market/marketplace-ui:${RELEASE_VERSION} volumes: - ../config/nginx/nginx.conf:/etc/nginx/nginx.conf @@ -23,8 +11,10 @@ services: restart: always ports: - "80:80" + networks: + - marketplace-network - service: + preview_service: image: ghcr.io/axonivy-market/marketplace-service:${RELEASE_VERSION} restart: always expose: @@ -44,6 +34,12 @@ services: - MARKET_JWT_SECRET_KEY=${MARKET_JWT_SECRET_KEY} - MARKET_CORS_ALLOWED_ORIGIN=${MARKET_CORS_ALLOWED_ORIGIN} - MARKET_MONGO_LOG_LEVEL=${MARKET_MONGO_LOG_LEVEL} + networks: + - marketplace-network + volumes: - mongodata: - marketcache: \ No newline at end of file + marketcache: + +networks: + marketplace-network: + external: true diff --git a/marketplace-ui/Dockerfile b/marketplace-ui/Dockerfile index b4359f3f0..e5b811f3e 100644 --- a/marketplace-ui/Dockerfile +++ b/marketplace-ui/Dockerfile @@ -9,7 +9,6 @@ RUN npm run build -- --configuration $BUILD_ENV # Stage 2: Serve Angular app using Nginx FROM nginx COPY --from=build-angular /app/dist/browser /usr/share/nginx/html -COPY --from=assets config/nginx/nginx.conf /etc/nginx/nginx.conf # Change ownership of the shared volume RUN mkdir -p /usr/share/nginx/html/market-cache diff --git a/marketplace-ui/src/environments/environment.development.ts b/marketplace-ui/src/environments/environment.development.ts index f2ae68edb..ec22f7b9e 100644 --- a/marketplace-ui/src/environments/environment.development.ts +++ b/marketplace-ui/src/environments/environment.development.ts @@ -1,6 +1,6 @@ export const environment = { production: false, - apiUrl: 'http://localhost:9090/marketplace-service', + apiUrl: 'http://localhost:8080', githubClientId: 'Iv23livu9HbsC4Q24eSC', githubAuthCallbackPath: '/auth/github/callback', dayInMiliseconds: 86400000