Skip to content

Commit

Permalink
Feature/MAPR-224 create dockerfile for deployment of marketplace (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhoan-axonivy authored Jul 25, 2024
1 parent 645420b commit fd97dfa
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 14 deletions.
44 changes: 31 additions & 13 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@ on:
push:
branches: [ "develop" ]
workflow_dispatch:
inputs:
build_env:
description: 'Build environment'
required: true
default: 'staging'

workflow_call:
inputs:
build_env:
description: 'Build environment'
required: true
type: string

jobs:
cleanup:
Expand Down Expand Up @@ -36,22 +47,29 @@ jobs:
SERVICE_PASSWORD: ${{ secrets.SERVICE_PASSWORD }}
MONGODB_DATABASE: ${{ secrets.MONGODB_DATABASE }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
MARKET_GITHUB_OAUTH_APP_CLIENT_ID: ${{ secrets.MARKET_GITHUB_OAUTH_APP_CLIENT_ID }}
MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET: ${{ secrets.MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET }}
MARKET_JWT_SECRET_KEY: ${{ secrets.MARKET_JWT_SECRET_KEY }}
run: |
sed -i "s/^MONGODB_INITDB_ROOT_USERNAME=.*$/MONGODB_INITDB_ROOT_USERNAME=$ROOT_USERNAME/" $ENV_FILE
sed -i "s/^MONGODB_INITDB_ROOT_PASSWORD=.*$/MONGODB_INITDB_ROOT_PASSWORD=$ROOT_PASSWORD/" $ENV_FILE
sed -i "s/^SERVICE_MONGODB_HOST=.*$/SERVICE_MONGODB_HOST=$MONGODB_HOST/" $ENV_FILE
sed -i "s/^SERVICE_MONGODB_DATABASE=.*$/SERVICE_MONGODB_DATABASE=$MONGODB_DATABASE/" $ENV_FILE
sed -i "s/^SERVICE_MONGODB_USER=.*$/SERVICE_MONGODB_USER=$SERVICE_USERNAME/" $ENV_FILE
sed -i "s/^SERVICE_MONGODB_PASSWORD=.*$/SERVICE_MONGODB_PASSWORD=$SERVICE_PASSWORD/" $ENV_FILE
sed -i "s/^MARKET_GITHUB_TOKEN=.*$/MARKET_GITHUB_TOKEN=$GH_TOKEN/" $ENV_FILE
sed -i "s/^MARKET_GITHUB_OAUTH_APP_CLIENT_ID=.*$/MARKET_GITHUB_OAUTH_APP_CLIENT_ID=$MARKET_GITHUB_OAUTH_APP_CLIENT_ID/" $ENV_FILE
sed -i "s/^MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=.*$/MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=$MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET/" $ENV_FILE
sed -i "s/^MARKET_JWT_SECRET_KEY=.*$/MARKET_JWT_SECRET_KEY=$MARKET_JWT_SECRET_KEY/" $ENV_FILE
if [ "${{ inputs.build_env }}" == "production" ]; then
OAUTH_APP_CLIENT_ID=${{ secrets.OAUTH_APP_CLIENT_ID }}
OAUTH_APP_CLIENT_SECRET=${{ secrets.OAUTH_APP_CLIENT_SECRET }}
else
OAUTH_APP_CLIENT_ID=${{ secrets.OAUTH_APP_CLIENT_ID_STAGING }}
OAUTH_APP_CLIENT_SECRET=${{ secrets.OAUTH_APP_CLIENT_SECRET_STAGING }}
fi
sed -i "s/^MONGODB_INITDB_ROOT_USERNAME=.*$/MONGODB_INITDB_ROOT_USERNAME=$ROOT_USERNAME/" $ENV_FILE
sed -i "s/^MONGODB_INITDB_ROOT_PASSWORD=.*$/MONGODB_INITDB_ROOT_PASSWORD=$ROOT_PASSWORD/" $ENV_FILE
sed -i "s/^SERVICE_MONGODB_HOST=.*$/SERVICE_MONGODB_HOST=$MONGODB_HOST/" $ENV_FILE
sed -i "s/^SERVICE_MONGODB_DATABASE=.*$/SERVICE_MONGODB_DATABASE=$MONGODB_DATABASE/" $ENV_FILE
sed -i "s/^SERVICE_MONGODB_USER=.*$/SERVICE_MONGODB_USER=$SERVICE_USERNAME/" $ENV_FILE
sed -i "s/^SERVICE_MONGODB_PASSWORD=.*$/SERVICE_MONGODB_PASSWORD=$SERVICE_PASSWORD/" $ENV_FILE
sed -i "s/^MARKET_GITHUB_TOKEN=.*$/MARKET_GITHUB_TOKEN=$GH_TOKEN/" $ENV_FILE
sed -i "s/^MARKET_GITHUB_OAUTH_APP_CLIENT_ID=.*$/MARKET_GITHUB_OAUTH_APP_CLIENT_ID=$OAUTH_APP_CLIENT_ID/" $ENV_FILE
sed -i "s/^MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=.*$/MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=$OAUTH_APP_CLIENT_SECRET/" $ENV_FILE
sed -i "s/^MARKET_JWT_SECRET_KEY=.*$/MARKET_JWT_SECRET_KEY=$MARKET_JWT_SECRET_KEY/" $ENV_FILE
- name: Build and bring up containers without cache
working-directory: ./marketplace-build
run: |
docker compose up --build --force-recreate -d
docker compose build --no-cache --build-arg BUILD_ENV=${{ inputs.build_env }}
docker compose up --force-recreate -d
6 changes: 6 additions & 0 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
description: 'Marketplace Docker image version'
required: true
default: 'latest'
build_env:
description: 'Build environment'
required: true
default: 'production'

env:
UI_IMAGE_NAME: marketplace-ui
Expand All @@ -19,6 +23,8 @@ jobs:
build:
name: Build Docker images
uses: ./.github/workflows/docker-build.yml
with:
build_env: ${{ inputs.build_env }}

release:
name: Tag and publish image to GH packages
Expand Down
2 changes: 2 additions & 0 deletions marketplace-build/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ services:
additional_contexts:
assets: ../marketplace-build/
dockerfile: Dockerfile
args:
- BUILD_ENV=${BUILD_ENV}
restart: always
volumes:
- ./config/nginx/nginx.conf:/etc/nginx/nginx.conf
Expand Down
3 changes: 2 additions & 1 deletion marketplace-ui/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Stage 1: Build Angular app
FROM node:20-alpine AS build-angular
ARG BUILD_ENV
WORKDIR /app
COPY . .
RUN npm install
RUN npm run build --prod
RUN npm run build -- --configuration $BUILD_ENV

# Stage 2: Serve Angular app using Nginx
FROM nginx
Expand Down
20 changes: 20 additions & 0 deletions marketplace-ui/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@
],
"outputHashing": "all"
},
"staging": {
"optimization": {
"scripts": true,
"styles": {
"minify": true,
"inlineCritical": false
},
"fonts": true
},
"outputHashing": "all",
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.staging.ts"
}
]
},
"development": {
"optimization": false,
"extractLicenses": false,
Expand All @@ -80,6 +97,9 @@
"production": {
"buildTarget": "marketplace-ui:build:production"
},
"staging": {
"buildTarget": "marketplace-ui:build:staging"
},
"development": {
"buildTarget": "marketplace-ui:build:development"
}
Expand Down
7 changes: 7 additions & 0 deletions marketplace-ui/src/environments/environment.staging.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const environment = {
production: false,
apiUrl: '/marketplace-service',
githubClientId: 'Ov23li5r26hRBOXZhtLV',
githubAuthCallbackPath: '/auth/github/callback',
dayInMiliseconds: 86400000
};

0 comments on commit fd97dfa

Please sign in to comment.