FROM swift:5.0.2
LABEL maintainer="IBM Swift Engineering at IBM Cloud"
LABEL Description="Template Dockerfile that extends the swift image."

# We can replace this port with what the user wants
EXPOSE 8080 1024 1025

# Default user if not provided
ARG bx_dev_user=root
ARG bx_dev_userid=1000

# Install system level packages
{{#ifCond serviceItems.length '>' 0}}
RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y \
{{#each serviceItems}}
  {{this.package}} \ {{/each}}
  && apt-get clean
{{else}}
# RUN apt-get update && apt-get dist-upgrade -y
{{/ifCond}}

# Include base Kitura dependencies
RUN apt-get update && apt-get install -y sudo libssl-dev libcurl4-openssl-dev

# Add utils files
ADD https://raw.githubusercontent.com/IBM-Swift/swift-ubuntu-docker/master/utils/tools-utils.sh /swift-utils/tools-utils.sh
ADD https://raw.githubusercontent.com/IBM-Swift/swift-ubuntu-docker/master/utils/common-utils.sh /swift-utils/common-utils.sh
RUN chmod -R 555 /swift-utils

# Create user if not root
RUN if [ "$bx_dev_user" != root ]; then useradd -ms /bin/bash -u $bx_dev_userid $bx_dev_user; fi

# Make password not required for sudo.
# This is necessary to run 'tools-utils.sh debug' script when executed from an interactive shell.
# This will not affect the deploy container.
RUN echo "$bx_dev_user ALL=NOPASSWD: ALL" > /etc/sudoers.d/user && \
    chmod 0440 /etc/sudoers.d/user

# Bundle application source & binaries
COPY . /swift-project
