-
Notifications
You must be signed in to change notification settings - Fork 0
66 lines (56 loc) · 1.96 KB
/
main.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
name: NestJS CI/CD pipeline
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
building:
name: Building and pushing image to AWS ECR
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Nodejs
uses: actions/setup-node@v4
with:
node-version: 18.20.0
- run: npm ci
- name: Creating .env file
run: |
echo DATABASE_URL=${{secrets.DATABASE_URL}} >> .env
echo JWT_SECRET=${{secrets.JWT_SECRET}} >> .env
echo AWS_ACCESS_KEY=${{secrets.AWS_ACCESS_KEY}} >> .env
echo AWS_SECRET_KEY=${{secrets.AWS_SECRET_KEY}} >> .env
echo AWS_S3_REGION=${{secrets.AWS_REGION}} >> .env
echo AWS_S3_BUCKET=${{secrets.AWS_BUCKET}} >> .env
echo POSTGRES_PASSWORD=${{secrets.DB_PASSWORD}} >> .env
echo POSTGRES_USER=${{secrets.DB_USER}} >> .env
echo POSTGRES_DB=${{secrets.DB}} >> .env
echo POSTGRES_PORT=${{secrets.DB_PORT}} >> .env
- name: checking file creation
run: |
ls -la
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ${{secrets.AWS_REGION}}
- name: Login to AWS ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Build,tag and push Docker image to AWS ECR
id: docker-image-build
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry}}
ECR_REPOSITORY: ${{ secrets.REPOSITORY_NAME}}
IMAGE_TAG: latest
run: |
echo "Building docker image......"
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
echo "Pushing docker image to AWS ECR......"
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "Done......."