|
| 1 | +ARG build=local |
| 2 | + |
| 3 | +# Environment |
| 4 | +FROM node:14.17-alpine3.14 AS environment |
| 5 | + |
| 6 | +ENV name="airseeker" \ |
| 7 | + appDir="/app" \ |
| 8 | + buildDir="/build" |
| 9 | +ENV packageDir="${buildDir}/package" |
| 10 | + |
| 11 | +# Build preparation |
| 12 | +FROM environment AS preparation |
| 13 | + |
| 14 | +WORKDIR ${buildDir} |
| 15 | + |
| 16 | +RUN apk add --update --no-cache git |
| 17 | + |
| 18 | +# Source preparation - local |
| 19 | +FROM preparation as sourcelocal |
| 20 | + |
| 21 | +COPY . ${buildDir} |
| 22 | + |
| 23 | +# Source preparation - git |
| 24 | +FROM preparation as sourcegit |
| 25 | + |
| 26 | +ARG branch=main |
| 27 | +ARG repository=https://github.com/api3dao/airseeker.git |
| 28 | + |
| 29 | +RUN git clone --single-branch --branch ${branch} ${repository} ${buildDir} |
| 30 | + |
| 31 | +# Production dependencies |
| 32 | +FROM source${build} AS deps |
| 33 | + |
| 34 | +RUN yarn install --production --no-optional --ignore-scripts |
| 35 | + |
| 36 | +# Production source code |
| 37 | +FROM source${build} AS build |
| 38 | + |
| 39 | +RUN yarn install && \ |
| 40 | + yarn build && \ |
| 41 | + yarn pack && \ |
| 42 | + mkdir -p ${packageDir} && \ |
| 43 | + tar -xf *.tgz -C ${packageDir} --strip-components 1 |
| 44 | + |
| 45 | +# Result image |
| 46 | +FROM environment |
| 47 | + |
| 48 | +ENV cronjob="/etc/cron.d/logrotate" |
| 49 | + |
| 50 | +WORKDIR ${appDir} |
| 51 | + |
| 52 | +LABEL application=${name} \ |
| 53 | + description="A tool to update a beacons with signed responses from Airnode's gateway" |
| 54 | + |
| 55 | +COPY --from=deps ${buildDir}/node_modules ./node_modules |
| 56 | +COPY --from=build ${packageDir} . |
| 57 | +COPY docker/entrypoint.sh /entrypoint.sh |
| 58 | +COPY docker/logrotate-crontab ${cronjob} |
| 59 | + |
| 60 | + # Create Airseeker user |
| 61 | +RUN addgroup -S ${name} && \ |
| 62 | + adduser -h ${appDir} -s /bin/false -S -D -H -G ${name} ${name} && \ |
| 63 | + chown -R ${name} ${appDir} && \ |
| 64 | + # Install pm2 |
| 65 | + yarn global add pm2 && \ |
| 66 | + # Install dependencies |
| 67 | + apk add --update --no-cache logrotate su-exec && \ |
| 68 | + # Clear any default logrotate configurations |
| 69 | + rm /etc/logrotate.d/* && \ |
| 70 | + # Enable logrotate cronjob |
| 71 | + chmod +x ${cronjob} && \ |
| 72 | + crontab -u ${name} ${cronjob} |
| 73 | + |
| 74 | +# Need to do this after the RUN directive because we first want to clear the /etc/logrotate.d directory |
| 75 | +COPY docker/pm2-airseeker /etc/logrotate.d/pm2-airseeker |
| 76 | + |
| 77 | +ENTRYPOINT ["/entrypoint.sh"] |
0 commit comments