FROM node:latest

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
COPY package*.json ./
COPY .npmrc ./
COPY yarn.lock ./
RUN yarn install --frozen-lockfile

# Build and test
COPY tsconfig.json ./
COPY ./src ./src
COPY gulpfile.mjs ./
RUN yarn build
RUN npm run test --if-present

# Remove source files
RUN rm -r ./src

ARG DOMAIN=example.com
ENV DOMAIN=$DOMAIN

ARG PORT=3000
ENV PORT=$PORT

EXPOSE $PORT
CMD [ "yarn", "start" ]