-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile-dev
88 lines (67 loc) · 2.31 KB
/
Dockerfile-dev
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
ARG RUBY_VERSION=3.2.2
FROM ruby:$RUBY_VERSION-slim AS base
# Install essential dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
file \
git \
gnupg2 \
imagemagick \
libpq-dev \
nodejs && rm -rf /var/lib/apt/lists/* # Cleanup to avoid permission issues
RUN mkdir -p /code
# Create a non-root user with a home directory and assign ownership to the user
RUN useradd -m -u 1001 -U -s /bin/sh -d /code appuser
RUN chown -R appuser:appuser /code
USER appuser
# Set the working directory
WORKDIR /code
# Switch to the non-root user
#USER appuser
#RUN chmod u+w /code
COPY . .
RUN bundle install
USER root
RUN if [ -n "$SOURCE_COMMIT" ] ; then echo $SOURCE_COMMIT > config/.git-revision ; fi
RUN chown -R appuser:appuser solr config docker public /code db/schema.rb
# Install supercronic - a cron alternative
ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.1.12/supercronic-linux-amd64 \
SUPERCRONIC=supercronic-linux-amd64 \
SUPERCRONIC_SHA1SUM=048b95b48b708983effb2e5c935a1ef8483d9e3e
RUN curl -fsSLO "$SUPERCRONIC_URL" \
&& echo "${SUPERCRONIC_SHA1SUM} ${SUPERCRONIC}" | sha1sum -c - \
&& chmod +x "$SUPERCRONIC" \
#&& mv "$SUPERCRONIC" "/tmp/${SUPERCRONIC}" \
#&& sudo mv "/tmp/${SUPERCRONIC}" "/usr/local/bin/${SUPERCRONIC}" \
&& mv "$SUPERCRONIC" "/usr/local/bin/${SUPERCRONIC}" \
&& ln -s "/usr/local/bin/${SUPERCRONIC}" /usr/local/bin/supercronic
# Switch back to the non-root user
USER appuser
# Set the entry point
ENTRYPOINT ["docker/entrypoint.sh"]
# Expose port 3000
EXPOSE 3000
# Development stage
FROM base AS development
# Command to start the Rails server in development mode
CMD bundle exec rails server -b 0.0.0.0
# Production stage
FROM base AS production
USER appuser
# Copy Gemfile and Gemfile.lock to the container
COPY Gemfile Gemfile.lock ./
# Install gems
RUN bundle check || bundle install
# Copy the application code
COPY . .
USER root
RUN mkdir -p /code/public/assets && chown -R appuser:appuser /code
RUN touch /code/tess.crontab && chown -R appuser:appuser /code/tess.crontab
USER appuser
# Precompile assets
RUN bundle exec rake assets:precompile
# Run the Rails server, bind for Docker
CMD bundle exec whenever > /code/tess.crontab \
&& (supercronic /code/tess.crontab &) \
&& bundle exec rails server -b 0.0.0.0