feat: made changes to dockerfile and error handling #21
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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......." | |