FROM alpine:latest

#ENV LD_LIBRARY_PATH=/lib


ENV PORT 8080
ENV NODE_ENV=dev

# the client version we will download from bumpx repo
ENV CLIENT_FILENAME instantclient-basic-linux.x64-12.1.0.1.0.zip





# Create and change to the app directory.
WORKDIR /usr/src/appTemp

# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
COPY ./docker/main.js ./docker/main.js
COPY ./package*.json ./


COPY ./docker/start.sh /usr/src/appEntry/start.sh

RUN apk --update --no-cache add \
	nodejs \
	nodejs-npm \
	tar


# Install production dependencies.
RUN npm install --cache=/usr/src/app/cache --production  && rm -rf /usr/src/app/cache && rm -rf /root/.npm

RUN apk del nodejs-npm


#RUN zip ./ –r ../appEntry/mydir.zip
RUN tar -czf ../appEntry/app.tar.gz ./* ; rm -rf ./*

#
#RUN wget https://download.oracle.com/otn_software/linux/instantclient/193000/instantclient-basic-linux.x64-19.3.0.0.0dbru.zip && \
#    unzip instantclient-basic-linux.x64-19.3.0.0.0dbru.zip && \
#    cp -r instantclient_19_3/* /lib && \
#    rm -rf instantclient-basic-linux.x64-19.3.0.0.0dbru.zip && \
#    apk add libaio && \
#    apk add --update libaio libnsl libc6-compat



#
##    ln -s /lib/libnsl.so.2 /lib/libnsl.so.1 ;\
#
#RUN ln -s /lib64/* /lib ;\
#    ln -s /lib/libnsl.so.2 /usr/lib/libnsl.so.1 ;\
#    ln -s /lib/libc.so /lib/libresolv.so.2 ;\
#    ln -s /usr/lib/libnsl.so.2 /usr/lib/libnsl.so.1
##    ln -s /lib/libclntsh.so.12.1 /lib/libclntsh.so ;


#RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
#apk add --update libaio libnsl && \
#ln -s /usr/lib/libnsl.so.2 /lib/libnsl.so.1

# Bug fix for segfault ( Convert PT_GNU_STACK program header into PT_PAX_FLAGS )
#RUN apk --update --no-cache add paxctl \
#	&& paxctl -cm $(which node)



# work in this directory
WORKDIR /opt/oracle/lib

# take advantage of this repo to easily download the client (use it at your own risk)
ADD https://github.com/bumpx/oracle-instantclient/raw/master/${CLIENT_FILENAME} .

# we need libaio and libnsl, the latter is only available as package in the edge repository
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
    apk add --update libaio libnsl && \
    ln -s /usr/lib/libnsl.so.2 /usr/lib/libnsl.so.1

# unzip the necessary libraries, create the base symlink and remove the zip file
RUN LIBS="*/libociei.so */libons.so */libnnz12.so */libclntshcore.so.12.1 */libclntsh.so.12.1" && \
    unzip ${CLIENT_FILENAME} ${LIBS} && \
    for lib in ${LIBS}; do mv ${lib} /usr/lib; done && \
    ln -s /usr/lib/libclntsh.so.12.1 /usr/lib/libclntsh.so && \
    rm ${CLIENT_FILENAME}




# Create and change to the app directory.
WORKDIR /usr/src/app


# Run the web service on container startup.
#CMD [ "node", "docker/index.js" ]
ENTRYPOINT ["/bin/sh", "/usr/src/appEntry/start.sh"]









