-
Notifications
You must be signed in to change notification settings - Fork 2
136 lines (118 loc) · 5.66 KB
/
docker-build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: Docker Build
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
release_version:
description: 'Release version'
required: true
type: string
default: ''
env:
BASE_WORKING_DIR: /home/axonivy/marketplace/work
jobs:
init:
name: Checking workspaces environment
runs-on: self-hosted
steps:
- run: |
if [ -n "${{ inputs.release_version }}" ]; then
echo "BASE_WORKING_DIR=/home/axonivy/marketplace/release" >> $GITHUB_ENV
fi
echo "Set workspaces to ${{ env.BASE_WORKING_DIR }}"
cleanup:
name: Clean up docker container and images
runs-on: self-hosted
needs: init
steps:
- name: Bring down and remove containers and images
continue-on-error: true
working-directory: ${{ env.BASE_WORKING_DIR }}/publish
run: |
docker compose down --rmi all
- name: Delete old sources code
continue-on-error: true
run: |
echo "Clean up workspaces ${{ env.BASE_WORKING_DIR }}"
rm -rf ${{ env.BASE_WORKING_DIR }}/*
mkdir -p ${{ env.BASE_WORKING_DIR }}
build-and-deploy:
name: Build and bring up docker containers
runs-on: self-hosted
needs: cleanup
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.release_version || github.ref }}
- name: Copy resouces 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: '${{ env.BASE_WORKING_DIR }}/publish/.env'
ROOT_USERNAME: ${{ secrets.MONGODB_ROOT_USERNAME }}
ROOT_PASSWORD: ${{ secrets.MONGODB_ROOT_PASSWORD }}
SERVICE_USERNAME: ${{ secrets.SERVICE_USERNAME }}
SERVICE_PASSWORD: ${{ secrets.SERVICE_PASSWORD }}
GH_MARKET_BRANCH: ${{ secrets.MARKET_GITHUB_MARKET_BRANCH }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
MARKET_JWT_SECRET_KEY: ${{ secrets.MARKET_JWT_SECRET_KEY }}
MARKET_CORS_ALLOWED_ORIGIN: ${{ secrets.MARKET_CORS_ALLOWED_ORIGIN }}
run: |
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_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_MARKET_BRANCH=.*$/MARKET_GITHUB_MARKET_BRANCH=$GH_MARKET_BRANCH/" $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
sed -i "s/^MARKET_CORS_ALLOWED_ORIGIN=.*$/MARKET_CORS_ALLOWED_ORIGIN=$MARKET_CORS_ALLOWED_ORIGIN/" $ENV_FILE
- name: Update version
if: ${{ inputs.release_version != '' }}
continue-on-error: true
env:
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: ${{ env.BASE_WORKING_DIR }}/publish
run: |
if [ -n "${{ inputs.release_version }}" ]; then
BUILD_VERSION="${{ inputs.release_version }}"
else
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
docker compose up --force-recreate -d