Skip to content

Commit

Permalink
MARP-1199 DEV instance refers to the config of the ci build (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhoan-axonivy authored Nov 1, 2024
1 parent 890ba49 commit 108b3d0
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 75 deletions.
43 changes: 35 additions & 8 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 }}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Release Build

on:
push:
branches: [ "master" ]
workflow_dispatch:
inputs:
release_version:
Expand Down
8 changes: 5 additions & 3 deletions marketplace-build/.env
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
27 changes: 13 additions & 14 deletions marketplace-build/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,32 +19,24 @@ 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.
* Login to GitHub Registry Hub.
* 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


Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
user www-data;
worker_processes auto;

events {}

http {
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions marketplace-build/dev/.env
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 1 addition & 4 deletions marketplace-build/dev/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Used for the local environment
name: marketplace

services:
ui:
container_name: marketplace-ui
build:
context: ../../marketplace-ui
additional_contexts:
assets: ../../marketplace-build/
dockerfile: Dockerfile
args:
- BUILD_ENV=${BUILD_ENV}
Expand All @@ -16,8 +15,6 @@ services:
- marketcache:/usr/share/nginx/html/market-cache
ports:
- "4200:80"
depends_on:
- service
networks:
- marketplace-network

Expand Down
24 changes: 2 additions & 22 deletions marketplace-build/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -59,8 +41,6 @@ services:
- BUILD_VERSION=${BUILD_VERSION}
ports:
- "8080:8080"
depends_on:
- mongodb

volumes:
mongodata:
Expand Down
2 changes: 2 additions & 0 deletions marketplace-build/release/.env
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
34 changes: 15 additions & 19 deletions marketplace-build/release/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
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
- marketcache:/usr/share/nginx/html/market-cache
restart: always
ports:
- "80:80"
networks:
- marketplace-network

service:
preview_service:
image: ghcr.io/axonivy-market/marketplace-service:${RELEASE_VERSION}
restart: always
expose:
Expand All @@ -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:
marketcache:

networks:
marketplace-network:
external: true
1 change: 0 additions & 1 deletion marketplace-ui/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion marketplace-ui/src/environments/environment.development.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 108b3d0

Please sign in to comment.