-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (64 loc) · 2.2 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
67
68
69
70
71
72
73
74
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: |
mkdir temp
touch temp/.env
touch temp/myfile.txt
echo DATABASE_URL=${{secrets.DATABASE_URL}} > temp/.env
echo JWT_SECRET=${{secrets.JWT_SECRET}} > temp/.env
echo AWS_ACCESS_KEY=${{secrets.AWS_ACCESS_KEY}} > temp/.env
echo AWS_SECRET_KEY=${{secrets.AWS_SECRET_KEY}} > temp/.env
echo AWS_S3_REGION=${{secrets.AWS_REGION}} > temp/.env
echo AWS_S3_BUCKET=${{secrets.AWS_BUCKET}} > temp/.env
echo POSTGRES_PASSWORD=${{secrets.DB_PASSWORD}} > temp/.env
echo POSTGRES_USER=${{secrets.DB_USER}} > temp/.env
echo POSTGRES_DB=${{secrets.DB}} > temp/.env
echo POSTGRES_PORT=${{secrets.DB_PORT}} > temp/.env
cat temp/.env
cat temp/myfile.txt
- name: checking file creation
run: |
ls -la
pwd
- 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......"
ls -la
pwd
docker buildx build --build-context generated=./temp -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
echo "Pushing docker image to AWS ECR......"
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "Done......."