-
Notifications
You must be signed in to change notification settings - Fork 21
115 lines (99 loc) · 3.96 KB
/
publishProjectFactory.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
name: Project Factory Service Test Builder
on:
push:
branches:
- "console"
- "master"
- "buildFixProjectFactory"
paths:
- 'health-services/project-factory/**'
pull_request:
branches:
- "console"
- "master"
- "buildFixProjectFactory"
jobs:
build:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch all history for tags and branches
# Step 2: Set up environment variables with clean BRANCH_NAME
- name: Set up environment variables
id: env
run: |
echo "ACTION_NUMBER=${GITHUB_RUN_NUMBER}" >> $GITHUB_ENV
# Check if it's a pull request
if [ "${{ github.event_name }}" == "pull_request" ]; then
BRANCH_NAME="${{ github.base_ref }}"
else
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
fi
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV
echo "COMMIT_ID=${GITHUB_SHA: -8}" >> $GITHUB_ENV
echo "Branch name is set to ${BRANCH_NAME}"
# Step 3: Build the service Docker image
- name: Build the service Docker image
id: docker_build
working-directory: ./health-services/project-factory
run: |
IMAGE_TAG=egovio/project-factory:${{ env.BRANCH_NAME }}-${{ env.COMMIT_ID }}-${{ env.ACTION_NUMBER }}
docker build . \
--file Dockerfile \
--tag $IMAGE_TAG
echo "::set-output name=image_name::$IMAGE_TAG"
echo "Service Docker image built successfully"
# Step 4: Build the database migration Docker image
- name: Build the DB migration Docker image
id: docker_db_build
working-directory: ./health-services/project-factory/migration
run: |
IMAGE_TAG=egovio/project-factory-db:${{ env.BRANCH_NAME }}-${{ env.ACTION_NUMBER }}
docker build . \
--file Dockerfile \
--tag $IMAGE_TAG
echo "::set-output name=db_image_name::$IMAGE_TAG"
echo "DB migration Docker image built successfully"
# Step 5: Login to Docker Hub and Push the service Docker image
- name: Login to Docker Hub and Push Docker Image
working-directory: ./health-services/project-factory
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
IMAGE_NAME: ${{ steps.docker_build.outputs.image_name }}
run: |
# Authenticate with Docker Hub
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
# Push the image to Docker Hub
docker push $IMAGE_NAME
echo "Docker image pushed: $IMAGE_NAME"
# Step 6: Login to Docker Hub and Push the DB migration Docker image
- name: Login to Docker Hub and Push DB Migration Docker Image
working-directory: ./health-services/project-factory/migration
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DB_IMAGE_NAME: ${{ steps.docker_db_build.outputs.db_image_name }}
run: |
# Authenticate with Docker Hub
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
# Push the image to Docker Hub
docker push $DB_IMAGE_NAME
echo "DB migration Docker image pushed: $DB_IMAGE_NAME"
node_build:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository
- uses: actions/checkout@v3
# Step 2: Set up Node.js environment
- uses: actions/setup-node@v2
with:
node-version: 20
# Step 3: Install dependencies and build for production
- name: Install dependencies and build
working-directory: ./health-services/project-factory
run: |
yarn install
yarn build