Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ name: Deploy to Production

on:
push:
branches: [main]
branches:
- main
- 'hotfix/**'

jobs:
build:
Expand Down
39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI - Staging

on:
push:
branches-ignore: [main]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: corepack enable && corepack prepare pnpm@10.33.0 --activate
- run: pnpm install --no-frozen-lockfile
- run: pnpm build
- run: pnpm test

docker:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set tag
id: meta
run: echo "branch=$(echo ${{ github.ref_name }} | sed 's/\//-/g')" >> $GITHUB_OUTPUT
- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- uses: docker/build-push-action@v4
with:
context: .
push: true
tags: |
chafah/nodejs-app:${{ steps.meta.outputs.branch }}-dev
chafah/nodejs-app:dev
72 changes: 72 additions & 0 deletions .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Deploy to Staging

on:
push:
branches:
- 'release/**'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: corepack enable && corepack prepare pnpm@10.33.0 --activate
- run: pnpm install --no-frozen-lockfile
- run: pnpm build
- run: pnpm test

docker:
needs: build
runs-on: ubuntu-latest
env:
NODE_ENV: staging
outputs:
image_tag: ${{ steps.meta.outputs.tag }}
steps:
- uses: actions/checkout@v4
- name: Set image tag
id: meta
run: |
BRANCH=$(echo ${{ github.ref_name }} | sed 's/\//-/g')
echo "tag=${BRANCH}-$(date +'%Y-%m-%d-%H%M%S')-staging" >> $GITHUB_OUTPUT
- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- uses: docker/build-push-action@v4
with:
context: .
push: true
build-args: NODE_ENV=staging
tags: |
chafah/nodejs-app:${{ steps.meta.outputs.tag }}
chafah/nodejs-app:staging

deploy:
needs: docker
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- run: aws eks update-kubeconfig --name landmark-eks-stg --region ${{ secrets.AWS_REGION }}
- name: Update image tag in k8s manifest
run: |
sed -i "s|image:.*|image: chafah/nodejs-app:${{ needs.docker.outputs.image_tag }}|" k8s/05-service/deployment-service.yaml
- name: Commit updated manifest to repo
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git add k8s/05-service/deployment-service.yaml
git commit -m "chore: update staging image to ${{ needs.docker.outputs.image_tag }}" || true
git push
- run: kubectl apply -f k8s/05-service/deployment-service.yaml
Loading