Br develop v1.0 #134
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: pr合并后打包并部署 | |
on: | |
pull_request: | |
types: | |
- closed # 分支关闭时 | |
jobs: | |
build: | |
if: github.event.pull_request.merged == true | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Checkout builder Label | |
run: | | |
if [[ "${{ github.event.pull_request.body }}" == *"<Auto>"* ]]; then | |
echo "Pull request body contains <Auto>. Proceeding with the workflow." | |
else | |
echo "Commit message does not contain <Auto>. Skipping the workflow." | |
exit 78 | |
fi | |
- name: Get Commit Info | |
id: extract | |
run: | | |
pull_request_body="${{ github.event.pull_request.body }}" | |
echo "Pull request body: $pull_request_body" | |
env="" | |
module="" | |
module_type="" | |
version="" | |
skip="" | |
docker_env="" | |
run_port="" | |
debug_port="" | |
if [[ "$pull_request_body" =~ -e:([^\ ]*) ]]; then | |
env="${BASH_REMATCH[1]}" | |
fi | |
if [[ "$pull_request_body" =~ -m:([^\ ]*) ]]; then | |
module="${BASH_REMATCH[1]}" | |
fi | |
if [[ "$commit_message" =~ -type:([^\ ]*) ]]; then | |
module_type="${BASH_REMATCH[1]}" | |
fi | |
if [[ "$pull_request_body" =~ -v:([^\ ]*) ]]; then | |
version="${BASH_REMATCH[1]}" | |
fi | |
if [[ "$pull_request_body" =~ -skip:([^\ ]*) ]]; then | |
skip="${BASH_REMATCH[1]}" | |
fi | |
if [[ "$pull_request_body" =~ -rp:([^\ ]*) ]]; then | |
run_port="${BASH_REMATCH[1]}" | |
fi | |
if [[ "$pull_request_body" =~ -dp:([^\ ]*) ]]; then | |
debug_port="${BASH_REMATCH[1]}" | |
fi | |
if [[ "$pull_request_body" =~ -de:\<([^>]+)\> ]]; then | |
docker_env="${BASH_REMATCH[1]}" | |
fi | |
echo "Environment: $env" | |
echo "Module: $module" | |
echo "Module_Type: $module_type" | |
echo "Version: $version" | |
echo "Skip: $skip" | |
echo "Run_Port: $run_port" | |
echo "Docker_Env: $docker_env" | |
echo "Debug_Port: $debug_port" | |
echo "ENV=$env" >> $GITHUB_ENV | |
echo "MODULE=$module" >> $GITHUB_ENV | |
echo "MODULE_TYPE=$module_type" >> $GITHUB_ENV | |
echo "VERSION=$version" >> $GITHUB_ENV | |
echo "SKIP=$skip" >> $GITHUB_ENV | |
echo "RUN_PORT=$run_port" >> $GITHUB_ENV | |
echo "DOCKER_ENV=$docker_env" >> $GITHUB_ENV | |
echo "DEBUG_PORT=$debug_port" >> $GITHUB_ENV | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '11' | |
distribution: 'temurin' | |
cache: maven | |
- name: Build with Maven | |
env: | |
JASYPT_ALGO: ${{ secrets.JASYPT_ALGO }} | |
JASYPT_PWD: ${{ secrets.JASYPT_PWD }} | |
run: | | |
if [ "${{ env.MODULE }}" == "Mixi-gateway" ]; then | |
cd Mixi-common | |
mvn install | |
cd .. | |
fi | |
if [ "${{ env.MODULE_TYPE }}" != "single" ]; then | |
cd $MODULE | |
fi | |
if [ "${{ env.MODULE }}" == "Mixi-gateway" ]; then | |
cd Mixi-gateway-config | |
fi | |
echo "LOWERCASE_MODULE=$(echo ${{ env.MODULE }} | awk '{print tolower($0)}')" >> $GITHUB_ENV | |
echo "jasypt:" > src/main/resources/you-cant-see-that.yml | |
echo " encryptor:" >> src/main/resources/you-cant-see-that.yml | |
echo " algorithm: $JASYPT_ALGO" >> src/main/resources/you-cant-see-that.yml | |
echo " password: $JASYPT_PWD" >> src/main/resources/you-cant-see-that.yml | |
if [ "${{ env.MODULE_TYPE }}" != "single" ]; then | |
cd .. | |
fi | |
mvn package -Dmaven.test.skip=true | |
- name: Build and Push Docker Images | |
if: ${{ env.SKIP != 'image'}} | |
env: | |
DOCKER_REPO: ${{ secrets.DOCKER_REPO }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_PWD }} | |
run: | | |
echo "Module Name: $MODULE" | |
if [ "${{ env.MODULE_TYPE }}" != "single" ]; then | |
cd $MODULE | |
fi | |
if [ "${{ env.MODULE }}" == "Mixi-gateway" ]; then | |
cd Mixi-gateway-app | |
fi | |
mkdir ./docker | |
cp ./Dockerfile ./docker | |
if [ "${{ env.MODULE }}" == "Mixi-gateway" ]; then | |
cd Mixi-gateway-app | |
cp ./target/*.jar ../docker | |
cd Mixi-gateway-config | |
cp ./target/*.jar ../docker | |
cd Mixi-gateway-infrastructure | |
cp ./target/*.jar ../docker | |
cd .. | |
fi | |
if [ "${{ env.MODULE }}" != "Mixi-gateway" ]; then | |
cp ./target/*.jar ./docker | |
fi | |
cd docker | |
if [ "${{ env.ENV }}" == "prod" ]; then | |
docker build --build-arg MODULE=${{ env.LOWERCASE_MODULE }} -t ${{ env.DOCKER_REPO }}/${{ env.LOWERCASE_MODULE }}:${{ env.VERSION }} . | |
else | |
docker build --build-arg MODULE=${{ env.LOWERCASE_MODULE }} --build-arg DEBUG_PORT=${{ env.DEBUG_PORT }} -t ${{ env.DOCKER_REPO }}/${{ env.LOWERCASE_MODULE }}:${{ env.VERSION }} . | |
fi | |
docker login -u $DOCKER_REPO -p $DOCKER_PASSWORD | |
docker push $DOCKER_REPO/${{ env.LOWERCASE_MODULE }}:$VERSION | |
- name: Choose the Server Host | |
if: ${{ env.ENV != ''}} | |
run: | | |
pwd="" | |
host="" | |
port="" | |
username="" | |
if [ "${{ env.ENV }}" == "prod" ] && [ "${{ env.MODULE }}" == "Mixi-user" ]; then | |
username="${{ secrets.MIXI_USER_PROD_USERNAME }}" | |
pwd="${{ secrets.MIXI_USER_PROD_PWD }}" | |
host="${{ secrets.MIXI_USER_PROD_ADDRESS }}" | |
port="${{ secrets.MIXI_USER_PROD_PORT }}" | |
elif [ "${{ env.ENV }}" == "prod" ] && [ "${{ env.MODULE }}" == "Mixi-audioVideo" ]; then | |
username="${{ secrets.MIXI_AUDO_VIDEO_PROD_USERNAME }}" | |
pwd="${{ secrets.MIXI_AUDO_VIDEO_PROD_PWD }}" | |
host="${{ secrets.MIXI_AUDO_VIDEO_PROD_ADDRESS }}" | |
port="${{ secrets.MIXI_AUDO_VIDEO_PROD_PORT }}" | |
elif [ "${{ env.ENV }}" == "prod" ] && [ "${{ env.MODULE }}" == "Mixi-server" ]; then | |
username="${{ secrets.MIXI_SERVER_PROD_USERNAME }}" | |
pwd="${{ secrets.MIXI_SERVER_PROD_PWD }}" | |
host="${{ secrets.MIXI_SERVER_PROD_ADDRESS }}" | |
port="${{ secrets.MIXI_SERVER_PROD_PORT }}" | |
elif [ "${{ env.ENV }}" == "prod" ] && [ "${{ env.MODULE }}" == "Mixi-webRoom" ]; then | |
username="${{ secrets.MIXI_WEB_ROOM_PROD_USERNAME }}" | |
pwd="${{ secrets.MIXI_WEB_ROOM_PROD_PWD }}" | |
host="${{ secrets.MIXI_WEB_ROOM_PROD_ADDRESS }}" | |
port="${{ secrets.MIXI_WEB_ROOM_PROD_PORT }}" | |
elif [ "${{ env.ENV }}" == "prod" ] && [ "${{ env.MODULE }}" == "Mixi-gateway" ]; then | |
username="${{ secrets.MIXI_GATEWAY_PROD_USERNAME }}" | |
pwd="${{ secrets.MIXI_GATEWAY_PROD_PWD }}" | |
host="${{ secrets.MIXI_GATEWAY_PROD_ADDRESS }}" | |
port="${{ secrets.MIXI_GATEWAY_PROD_PORT }}" | |
elif [ "${{ env.ENV }}" == "test" ] && [ "${{ env.MODULE }}" == "Mixi-user" ]; then | |
username="${{ secrets.MIXI_USER_TEST_USERNAME }}" | |
pwd="${{ secrets.MIXI_USER_TEST_PWD }}" | |
host="${{ secrets.MIXI_USER_TEST_ADDRESS }}" | |
port="${{ secrets.MIXI_USER_TEST_PORT }}" | |
elif [ "${{ env.ENV }}" == "test" ] && [ "${{ env.MODULE }}" == "Mixi-audioVideo" ]; then | |
username="${{ secrets.MIXI_AUDO_VIDEO_TEST_USERNAME }}" | |
pwd="${{ secrets.MIXI_AUDO_VIDEO_TEST_PWD }}" | |
host="${{ secrets.MIXI_AUDO_VIDEO_TEST_ADDRESS }}" | |
port="${{ secrets.MIXI_AUDO_VIDEO_TEST_PORT }}" | |
elif [ "${{ env.ENV }}" == "test" ] && [ "${{ env.MODULE }}" == "Mixi-server" ]; then | |
username="${{ secrets.MIXI_SERVER_TEST_USERNAME }}" | |
pwd="${{ secrets.MIXI_SERVER_TEST_PWD }}" | |
host="${{ secrets.MIXI_SERVER_TEST_ADDRESS }}" | |
port="${{ secrets.MIXI_SERVER_TEST_PORT }}" | |
elif [ "${{ env.ENV }}" == "test" ] && [ "${{ env.MODULE }}" == "Mixi-webRoom" ]; then | |
username="${{ secrets.MIXI_WEB_ROOM_TEST_USERNAME }}" | |
pwd="${{ secrets.MIXI_WEB_ROOM_TEST_PWD }}" | |
host="${{ secrets.MIXI_WEB_ROOM_TEST_ADDRESS }}" | |
port="${{ secrets.MIXI_WEB_ROOM_TEST_PORT }}" | |
elif [ "${{ env.ENV }}" == "test" ] && [ "${{ env.MODULE }}" == "Mixi-gateway" ]; then | |
username="${{ secrets.MIXI_GATEWAY_TEST_USERNAME }}" | |
pwd="${{ secrets.MIXI_GATEWAY_TEST_PWD }}" | |
host="${{ secrets.MIXI_GATEWAY_TEST_ADDRESS }}" | |
port="${{ secrets.MIXI_GATEWAY_TEST_PORT }}" | |
else | |
echo "Invalid environment" | |
exit 1 | |
fi | |
echo "USERNAME=$username" >> $GITHUB_ENV | |
echo "PWD=$pwd" >> $GITHUB_ENV | |
echo "HOST=$host" >> $GITHUB_ENV | |
echo "PORT=$port" >> $GITHUB_ENV | |
- name: Connect Server | |
uses: appleboy/ssh-action@master | |
with: | |
# 同上述 | |
host: ${{ env.HOST }} | |
username: ${{ env.USERNAME }} | |
password: ${{ env.PWD }} | |
port: ${{ env.PORT }} | |
# ssh进入系统后执行什么样的操作。一般是关闭原有的服务在重启 | |
script: | | |
if [ "${{ env.RUN_PORT }}" != "" ]; then | |
stop_docker_name=$(docker ps --filter "expose=${{ env.RUN_PORT }}" --format "{{.Names}}") | |
if [ "$stop_docker_name" != "" ]; then | |
docker stop $stop_docker_name | |
fi | |
docker rm ${{ env.MODULE }}-${{ env.VERSION }} | |
docker rmi ${{ secrets.DOCKER_REPO }}/${{ env.LOWERCASE_MODULE }}:${{ env.VERSION }} | |
docker pull ${{ secrets.DOCKER_REPO }}/${{ env.LOWERCASE_MODULE }}:${{ env.VERSION }} | |
if [ "${{ env.ENV }}" == "prod" ]; then | |
docker run -p ${{env.RUN_PORT}}:${{env.RUN_PORT}} --name ${{ env.MODULE }}-${{ env.VERSION }} ${{env.DOCKER_ENV}} -d ${{ secrets.DOCKER_REPO }}/${{ env.LOWERCASE_MODULE }}:${{ env.VERSION }} | |
elif [ "${{ env.DEBUG_PORT }}" != "" ]; then | |
docker run -p ${{env.RUN_PORT}}:${{env.RUN_PORT}} -p ${{env.DEBUG_PORT}}:${{env.DEBUG_PORT}} --name ${{ env.MODULE }}-${{ env.VERSION }} ${{env.DOCKER_ENV}} -d ${{ secrets.DOCKER_REPO }}/${{ env.LOWERCASE_MODULE }}:${{ env.VERSION }} | |
else | |
docker run -p ${{env.RUN_PORT}}:${{env.RUN_PORT}} --name ${{ env.MODULE }}-${{ env.VERSION }} ${{env.DOCKER_ENV}} -d ${{ secrets.DOCKER_REPO }}/${{ env.LOWERCASE_MODULE }}:${{ env.VERSION }} | |
fi | |
fi |