Skip to content

Commit ac847ee

Browse files
committed
ci: Update ci workflow
1 parent daabe24 commit ac847ee

File tree

4 files changed

+133
-133
lines changed

4 files changed

+133
-133
lines changed

.github/workflows/ci-cd-pipeline.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
trigger-full-ci:
3838
# Triggers the full CI/CD pipeline.
3939
name: CI
40-
uses: ./.github/workflows/lint-build-publish.yml
40+
uses: ./.github/workflows/lint.yml
4141
secrets: inherit
4242
with:
4343
target_env: ${{ github.ref == 'refs/heads/main' && 'production' || github.ref == 'refs/heads/development' && 'development' || 'invalid' }}

.github/workflows/deploy.yml

Lines changed: 0 additions & 85 deletions
This file was deleted.

.github/workflows/lint.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Lint
2+
run-name: Lint
3+
4+
permissions:
5+
contents: read
6+
actions: read
7+
8+
on:
9+
workflow_call:
10+
inputs:
11+
node-version:
12+
description: "Node.js version to use"
13+
required: true
14+
type: string
15+
target_env:
16+
description: 'The deployment environment e.g. production or development'
17+
required: true
18+
type: string
19+
skip_deploy:
20+
description: 'Skip the deploy step (true/false)'
21+
required: true
22+
type: boolean
23+
24+
jobs:
25+
lint:
26+
name: Run Lint
27+
runs-on: ubuntu-latest
28+
environment: ${{ inputs.target_env }}
29+
30+
steps:
31+
- name: Checkout code
32+
# Checks out the repository code.
33+
uses: actions/checkout@v4
34+
35+
- name: Setup Node.js (Latest)
36+
# Sets up NodeJS environment
37+
uses: actions/setup-node@v4
38+
with:
39+
node-version: ${{ inputs.node-version }}
40+
41+
- name: Install Dependencies
42+
# Installs dependencies
43+
run: npm ci
44+
45+
- name: Run Linter
46+
# Runs lint checks
47+
run: npm run lint
48+
49+
trigger-deploy:
50+
needs: lint
51+
name: Deploy
52+
if: ${{ inputs.skip_deploy == false }}
53+
uses: ./.github/workflows/publish-and-deploy.yml
54+
secrets: inherit
55+
with:
56+
target_env: ${{ inputs.target_env }}
57+
target_tag: ${{ needs.build.outputs.target_tag }}
Lines changed: 75 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,20 @@
1-
name: Lint, Build & Publish
2-
run-name: Lint, Build & Publish
3-
4-
permissions:
5-
contents: read
6-
actions: read
1+
name: Publish & Deploy
2+
run-name: Publish & Deploy
73

84
on:
95
workflow_call:
106
inputs:
11-
node-version:
12-
description: "Node.js version to use"
7+
target_tag:
138
required: true
149
type: string
10+
description: 'The deployment target tag, e.g. prod-latest or dev-latest'
1511
target_env:
16-
description: 'The deployment environment e.g. production or development'
1712
required: true
1813
type: string
19-
skip_deploy:
20-
description: 'Skip the deploy step (true/false)'
21-
required: true
22-
type: boolean
14+
description: 'The deployment environment e.g. production or development'
2315

2416
jobs:
25-
lint:
26-
name: Run Lint
27-
runs-on: ubuntu-latest
28-
environment: ${{ inputs.target_env }}
29-
30-
steps:
31-
- name: Checkout code
32-
# Checks out the repository code.
33-
uses: actions/checkout@v4
34-
35-
- name: Setup Node.js (Latest)
36-
# Sets up NodeJS environment
37-
uses: actions/setup-node@v4
38-
with:
39-
node-version: ${{ inputs.node-version }}
40-
41-
- name: Install Dependencies
42-
# Installs dependencies
43-
run: npm ci
44-
45-
- name: Run Linter
46-
# Runs lint checks
47-
run: npm run lint
48-
49-
build:
50-
needs: lint
17+
publish:
5118
name: Build Docker Images
5219
runs-on: ubuntu-latest
5320
environment: ${{ inputs.target_env }}
@@ -190,12 +157,73 @@ jobs:
190157
191158
docker push $IMAGE
192159
193-
trigger-deploy:
194-
needs: build
160+
deploy:
161+
needs: publish
195162
name: Deploy
196-
if: ${{ inputs.skip_deploy == false }}
197-
uses: ./.github/workflows/deploy.yml
198-
secrets: inherit
199-
with:
200-
target_env: ${{ inputs.target_env }}
201-
target_tag: ${{ needs.build.outputs.target_tag }}
163+
runs-on: ubuntu-latest
164+
environment: ${{ inputs.target_env }}
165+
steps:
166+
- name: Checkout code
167+
# Checks out the repository code.
168+
uses: actions/checkout@v4
169+
170+
- name: Set up SSH key
171+
# Sets up the SSH key for the server.
172+
run: |
173+
# Create the .ssh directory if it doesn't exist.
174+
mkdir -p ~/.ssh
175+
# Write the SSH private key to file.
176+
echo "${{ secrets.DEPLOYMENT_SSH_KEY }}" > ~/.ssh/id_rsa
177+
chmod 600 ~/.ssh/id_rsa
178+
# Add the server to known_hosts to avoid authenticity prompts.
179+
ssh-keyscan -H ${{ secrets.DEPLOYMENT_SERVER }} >> ~/.ssh/known_hosts
180+
181+
- name: Upload deployment files to server
182+
# Creates project directory and uploads required files to server
183+
run: |
184+
# create env file
185+
echo "${{ secrets.APPLICATION_ENV_FILE }}" > ./config/env/.env
186+
187+
# copy all config files over
188+
ssh -o StrictHostKeyChecking=no ${{ secrets.DEPLOYMENT_SSH_USER }}@${{ secrets.DEPLOYMENT_SERVER }} \
189+
"mkdir -p /opt/rcb-deployments/${{ vars.PROJECT_NAME }}/config /opt/rcb-deployments/${{ vars.PROJECT_NAME }}/docker"
190+
191+
scp -r -o StrictHostKeyChecking=no ./config/* \
192+
${{ secrets.DEPLOYMENT_SSH_USER }}@${{ secrets.DEPLOYMENT_SERVER }}:/opt/rcb-deployments/${{ vars.PROJECT_NAME }}/config/
193+
194+
# copy compose files
195+
scp -o StrictHostKeyChecking=no docker/docker-compose.yml ${{ secrets.DEPLOYMENT_SSH_USER }}@${{ secrets.DEPLOYMENT_SERVER }}:/opt/rcb-deployments/${{ vars.PROJECT_NAME }}/docker/docker-compose.yml
196+
if [ "${{ inputs.target_tag }}" = "prod-latest" ]; then
197+
scp -o StrictHostKeyChecking=no docker/docker-compose.prod.yml ${{ secrets.DEPLOYMENT_SSH_USER }}@${{ secrets.DEPLOYMENT_SERVER }}:/opt/rcb-deployments/${{ vars.PROJECT_NAME }}/docker/docker-compose.override.yml
198+
scp -o StrictHostKeyChecking=no otel-config.yaml ${{ secrets.DEPLOYMENT_SSH_USER }}@${{ secrets.DEPLOYMENT_SERVER }}:/opt/rcb-deployments/${{ vars.PROJECT_NAME }}/otel-config.yaml
199+
else
200+
scp -o StrictHostKeyChecking=no docker/docker-compose.dev.yml ${{ secrets.DEPLOYMENT_SSH_USER }}@${{ secrets.DEPLOYMENT_SERVER }}:/opt/rcb-deployments/${{ vars.PROJECT_NAME }}/docker/docker-compose.override.yml
201+
fi
202+
203+
# copy deploy script
204+
scp -o StrictHostKeyChecking=no scripts/deploy.sh ${{ secrets.DEPLOYMENT_SSH_USER }}@${{ secrets.DEPLOYMENT_SERVER }}:/opt/rcb-deployments/${{ vars.PROJECT_NAME }}/deploy.sh
205+
ssh -o StrictHostKeyChecking=no ${{ secrets.DEPLOYMENT_SSH_USER }}@${{ secrets.DEPLOYMENT_SERVER }} "\
206+
chmod +x /opt/rcb-deployments/${{ vars.PROJECT_NAME }}/deploy.sh"
207+
208+
- name: Deploy to VPS
209+
# Deploys to VPS.
210+
run: |
211+
OWNER="${{ vars.GHCR_OWNER }}"
212+
APPLICATION_API_IMAGE="ghcr.io/$OWNER/${{ github.event.repository.name }}-api:${{ inputs.target_tag }}"
213+
APPLICATION_JOBS_IMAGE="ghcr.io/$OWNER/${{ github.event.repository.name }}-jobs:${{ inputs.target_tag }}"
214+
echo "Deploying to VPS..."
215+
ssh -o StrictHostKeyChecking=no ${{ secrets.DEPLOYMENT_SSH_USER }}@${{ secrets.DEPLOYMENT_SERVER }} "\
216+
217+
# exports general variables
218+
export PROJECT_NAME='${{ vars.PROJECT_NAME }}' && \
219+
export GHCR_USER='${{ secrets.MACHINE_USER }}' && \
220+
export GHCR_PAT='${{ secrets.MACHINE_PAT }}' && \
221+
export APPLICATION_API_IMAGE='$APPLICATION_API_IMAGE' && \
222+
export APPLICATION_JOBS_IMAGE='$APPLICATION_JOBS_IMAGE' && \
223+
224+
# applies only to production for logging
225+
export HONEYCOMB_API_KEY='${{ secrets.HONEYCOMB_API_KEY }}' && \
226+
export HONEYCOMB_DATASET='${{ secrets.HONEYCOMB_DATASET }}' && \
227+
228+
# runs deploy script
229+
/opt/rcb-deployments/${{ vars.PROJECT_NAME }}/deploy.sh"

0 commit comments

Comments
 (0)