This repository has been archived by the owner on Jul 13, 2022. It is now read-only.
forked from archivy/archivy-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile.source
126 lines (113 loc) · 6.31 KB
/
Dockerfile.source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
######## Dockerfile for Archivy Built On Alpine Linux ########
# #
#####################################################################
# CONTAINERISED ARCHIVY BUILT ON TOP OF ALPINE LINUX #
#####################################################################
# #
# This Dockerfile does the following: #
# #
# 1. Starts with a base image of Python3.9 built on Alpine #
# Linux. #
# 2. Adds 'testing' repository, and installs required packages. #
# 3. Clones the 'archivy' repository and installs Archivy. #
# 4. Cleans up by deleting packages and cloned repository. #
# 5. Adds a non-root user and group to run Archivy, creates the #
# directory which Archivy uses to store its data, and changes #
# ownership of all files in the non-root user's home dir. #
# 6. Copies the entrypoint.sh and healthcheck.sh scripts from #
# the host. The ownership of all copied files is set to #
# archivy user and group. #
# 7. Sets the 'run as' user to 'archivy'. #
# 8. Creates a mount point so that external volumes can be #
# mounted/attached to it. Useful for data persistence. #
# 9. Exposes port 5000 on the container. #
# 10. Sets a command which will be to check the health of the #
# container. #
# 11. Runs the startup script as the entrypoint command with #
# the "run" argument. #
# #
# Note : Do not forget to bind port 5000 to a port on your host if #
# you wish to access the server. Also, if you want your data #
# to persist, bind-mount a directory to the container. #
# #
# Example: #
# docker run --name archivy -p 5000:5000 -v \ #
# "$(pwd)"/testDir:/archivy/data archivy:source #
# #
# where 'testDir' is the directory on the host and #
# '/archivy/data' is the path of the volume on the #
# container(fixed in Dockerfile). #
# #
#####################################################################
# Start with python3.9-alpine
FROM python:3.9-alpine
# ARG values for injecting metadata during build time
# NOTE: When using ARGS in a multi-stage build, remember to redeclare
# them for the stage that needs to use it. ARGs last only for the
# lifetime of the stage that they're declared in.
ARG BUILD_DATE
ARG VCS_REF
# Setting VCS URL
ARG ARCHIVY_VCS_URL="https://github.com/archivy/archivy"
# Add 'testing' repository and install dependencies
RUN echo "@testing http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
&& apk update && apk add --no-cache \
git \
build-base \
# Clone the repository
&& git clone ${ARCHIVY_VCS_URL} \
&& cd archivy \
# Install all necessary files/packages
&& python3.9 setup.py install \
# Delete git package
&& apk del git --purge \
&& cd ../ \
# Remove downloaded source code
&& rm -rf archivy \
&& addgroup -S -g 1000 archivy \
&& adduser -h /archivy -g "User account for running Archivy" \
-s /sbin/nologin -S -D -G archivy -u 1000 archivy \
# Creating directory in which Archivy's files will be stored
# (If this directory isn't created, Archivy exits with a "permission denied" error)
&& mkdir -p /archivy/data \
# Changing ownership of all files in user's home directory
&& chown -R archivy:archivy /archivy
# Copying entrypoint and healthcheck script from host
COPY --chown=archivy:archivy entrypoint.sh healthcheck.sh /usr/local/bin/
# Run as user 'archivy'
USER archivy
# Creating mount point for persistent data
VOLUME /archivy/data
# Exposing port 5000
EXPOSE 5000
# System call signal that will be sent to the container to exit
STOPSIGNAL SIGTERM
# Healthcheck command used to check if Archivy is up and running
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=5 CMD healthcheck.sh
# Entrypoint - Run 'entrypoint.sh' script. Any command given to 'docker container run' will be added as an argument
# to the ENTRYPOINT command below. The 'entrypoint.sh' script needs to receive 'start' as an argument in order to set up
# the Archivy server.
ENTRYPOINT ["entrypoint.sh"]
# The 'run' CMD is required by the 'entrypoint.sh' script to set up the Archivy server.
# Any command given to the 'docker container run' will override the CMD below.
CMD ["run"]
# Labels
LABEL org.opencontainers.image.vendor="Uzay G" \
org.opencontainers.image.authors="https://github.com/Uzay-G" \
org.opencontainers.image.title="Archivy" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.url="https://github.com/archivy/archivy/tree/master/" \
org.label-schema.vcs-url="https://github.com/archivy/archivy/tree/master/" \
org.opencontainers.image.documentation="https://github.com/archivy/archivy/blob/master/README.md" \
org.opencontainers.image.source="https://github.com/archivy/archivy/blob/docker/Dockerfile.source" \
org.opencontainers.image.description="Archivy is a self-hosted knowledge repository that \
allows you to safely preserve useful content that contributes to your knowledge bank." \
org.opencontainers.image.created=$BUILD_DATE \
org.label-schema.build-date=$BUILD_DATE \
org.opencontainers.image.revision=$VCS_REF \
org.label-schema.vcs-ref=$VCS_REF \
org.opencontainers.image.version="source" \
org.label-schema.version="source" \
org.label-schema.schema-version="1.0" \
software.author.repository="https://github.com/archivy/archivy" \
software.release.version="source"