diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..b7848d9 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,42 @@ +name: Docker Image CI/CD + +on: + push: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: pulling the latest code + run: | + pwd + ls -alsh + git branch + git switch main + git pull + + - name: Configure AWS credentials + run: | + echo "AWS_ACCESS_KEY_ID=${{ secrets.ACCESS_KEY }}" >> $GITHUB_ENV + echo "AWS_SECRET_ACCESS_KEY=${{ secrets.SECRET_ACCESS }}" >> $GITHUB_ENV + echo "AWS_REGION=us-east-1" >> $GITHUB_ENV + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + + - name: building the docker image + run: | + pwd + docker build -t cicd-backend . + docker images + + - name: push the image to ecr + run: | + docker tag cicd-backend:latest 119688269608.dkr.ecr.us-east-1.amazonaws.com/cicd-backend:latest + docker push 119688269608.dkr.ecr.us-east-1.amazonaws.com/cicd-backend:latest diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a8fd89d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +# Use an official Node.js runtime as the base image +FROM node:21.7.3-alpine3.20 + +# Set the working directory in the container to /app +WORKDIR /app + +# Copy package.json and package-lock.json to the working directory +COPY package*.json ./ + +# Install the application dependencies +RUN npm install + +# Copy the rest of the application code to the working directory +COPY . . + +# Make port 8080 available outside the container +EXPOSE 3000 + +# Define the command to run the application +CMD [ "npm", "start" ]