diff --git a/.github/workflows/docker-pipeline.yaml b/.github/workflows/docker-pipeline.yaml new file mode 100644 index 000000000..3a98c0266 --- /dev/null +++ b/.github/workflows/docker-pipeline.yaml @@ -0,0 +1,31 @@ +name: CI/CD nodejs image + +on: + push: + branches: + - "main" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Login to Docker Hub + run: docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_SECRET }} + + - name: Build the Docker image + run: docker build --tag ${{ secrets.DOCKER_USER }}/${{ secrets.DOCKER_IMAGE_NAME }}:${{ github.sha }} . + + - name: Set image id from the last build + id: vars + run: echo "::set-output name=image_id::$(docker images | grep ${{ secrets.DOCKER_USER }}\/${{ secrets.DOCKER_IMAGE_NAME }} | head -n1 | awk '{print $3}')" + + - name: Retag image LATEST with image id from the last build + run: docker tag ${{ steps.vars.outputs.image_id }} ${{ secrets.DOCKER_USER }}/${{ secrets.DOCKER_IMAGE_NAME }}:latest + + - name: Docker Push + run: | + docker push ${{ secrets.DOCKER_USER }}/${{ secrets.DOCKER_IMAGE_NAME }}:${{ github.sha }} + docker push ${{ secrets.DOCKER_USER }}/${{ secrets.DOCKER_IMAGE_NAME }}:latest \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..a4e444787 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +# Use an official Node.js runtime as a parent image +FROM node:14-alpine + +# Set the working directory to /app +WORKDIR /app + +# Copy the package.json and package-lock.json files to the container +COPY package*.json ./ + +# Install dependencies +RUN npm install + +# Copy the rest of the application files to the container +COPY . . + +# Set the environment variable for the application's port +ENV PORT=80 + +# Expose the port that the application will listen on +EXPOSE $PORT + +# Start the application +CMD [ "npm", "start" ]