From 58d6ccf6c6713a694151197b24b2aa4d5441697d Mon Sep 17 00:00:00 2001 From: irvanfebri Date: Tue, 24 Oct 2023 10:05:57 +0700 Subject: [PATCH] add dockerfile v.1.1 --- Dockerfile | 29 +++++++++++++++++++++++++++++ build_push_image.sh | 10 ++++++++++ 2 files changed, 39 insertions(+) create mode 100644 Dockerfile create mode 100644 build_push_image.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..72a2175de --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# Use Node.js version 14 as the base image +FROM node:14 + +# Set the working directory inside the container to /src +WORKDIR /src + +# Copy package.json and package-lock.json to the working directory +COPY package*.json ./ + +# Install dependencies using npm +RUN npm install + +# Download the wait-for-it.sh script from the repository +RUN wget -O ./wait-for-it.sh https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh + +# Make the wait-for-it.sh script executable +RUN chmod +x ./wait-for-it.sh + +# Copy the index.js file to the working directory +COPY index.js ./ + +# Set the environment variable PORT to 3001 +ENV PORT=3001 + +# Expose the specified port +EXPOSE $PORT + +# Define the command to run the application after waiting for RabbitMQ to start +CMD ["sh", "-c", "./wait-for-it.sh my-rabbitmq:5672 --timeout=30 -- node index.js"] diff --git a/build_push_image.sh b/build_push_image.sh new file mode 100644 index 000000000..d5af221ea --- /dev/null +++ b/build_push_image.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Build Docker image +docker build -t ghcr.io/irvanfebri/shipping-service:latest . + +# Log in to GitHub Container Registry +echo $GH_PACKAGES_TOKEN | docker login ghcr.io -u irvanfebri --password-stdin + +# Push Docker image to GitHub Container Registry +docker push ghcr.io/irvanfebri/shipping-service:latest