FROM node:12

# Get PACKAGECLOUD_TOKEN from --build-arg PACKAGECLOUD_TOKEN=<> option
ARG PACKAGECLOUD_TOKEN

# Create a directory
RUN mkdir -p /home/node/gateway-social-auth
RUN chown -R node:node /home/node/gateway-social-auth

# Change user
USER node

# Change to working directory
WORKDIR /home/node/gateway-social-auth

# Copy files required to fetch dependency
COPY package.json ./
COPY yarn.lock ./

# Download a .npmrc with auth token for access to @orchard packages
RUN curl -s https://$PACKAGECLOUD_TOKEN:@packagecloud.io/install/repositories/orchardit/npm/script.node.sh | bash

# Install Dependencies
RUN yarn install --frozen-lockfile

# Copy application code
COPY --chown=node:node . .

# Build the project
RUN yarn build

# Set port environment variable
ENV PORT 8080

# Expose 8080 to the interface
EXPOSE 8080

# Start the server
CMD [ "yarn", "start"]
