-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile.erb
More file actions
99 lines (86 loc) · 3.99 KB
/
Dockerfile.erb
File metadata and controls
99 lines (86 loc) · 3.99 KB
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
FROM node:20.15.1-alpine AS builder
RUN apk add --no-cache git
WORKDIR /app
COPY frontend/package.json frontend/yarn.lock ./
RUN yarn install --pure-lockfile
COPY frontend .
RUN yarn build
<% if @schema['@backend'] == 'laravel' %>
FROM php:8.0-apache
ENV CFLAGS="$CFLAGS -D_GNU_SOURCE"
<% if @schema['@db'] == 'mssql' %>ENV ACCEPT_EULA=Y<% end %>
RUN apt-get update && apt-get install -y libpq-dev openssl zip unzip git vim
# Configure PHP for Cloud Run.
# Precompile PHP code with opcache.
<% if @schema['@db'] == 'postgresql' %>RUN docker-php-ext-install -j "$(nproc)" opcache pdo pdo_pgsql pgsql sockets<% end %>
<% if @schema['@db'] == 'mssql' %>RUN apt-get update && apt-get install -y gnupg2
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get -y --no-install-recommends install msodbcsql18 unixodbc-dev
RUN pecl install sqlsrv
RUN pecl install pdo_sqlsrv
RUN docker-php-ext-enable sqlsrv pdo_sqlsrv<% end %>
<% if @schema['@db'] == 'mysql' %>RUN docker-php-ext-install -j "$(nproc)" opcache pdo pdo_mysql sockets<% end %>
RUN set -ex; \
{ \
echo "; Cloud Run enforces memory & timeouts"; \
echo "memory_limit = -1"; \
echo "max_execution_time = 0"; \
echo "; File upload at Cloud Run network limit"; \
echo "upload_max_filesize = 32M"; \
echo "post_max_size = 32M"; \
echo "; Configure Opcache for Containers"; \
echo "opcache.enable = On"; \
echo "opcache.validate_timestamps = Off"; \
echo "; Configure Opcache Memory (Application-specific)"; \
echo "opcache.memory_consumption = 32"; \
} > "$PHP_INI_DIR/conf.d/cloud-run.ini"
# Copy in custom code from the host machine.
WORKDIR /var/www/html
COPY ./backend ./backend
COPY --from=builder /app/build /var/www/html/backend/public
WORKDIR /var/www/html/backend
# Get Composer and insall php dependencies
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer update && composer install
# Setup new Apache document root
ENV APACHE_DOCUMENT_ROOT=/var/www/html/backend/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
# Enable mod rewrite
RUN a2enmod rewrite headers
# Use the PORT environment variable in Apache configuration files.
# https://cloud.google.com/run/docs/reference/container-contract#port
RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf
# Configure PHP for development.
# Switch to the production php.ini for production operations.
# RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
# https://github.com/docker-library/docs/blob/master/php/README.md#configuration
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
# Allow Apache to access a source code and .htaccess file
RUN chmod -R 755 /var/www/html/backend/ && chmod 644 /var/www/html/backend/public/.htaccess && chmod -R 777 /var/www/html/backend/storage/
# Do laravel prepartions and start Apache
CMD php artisan key:generate && php artisan jwt:secret && php artisan migrate && php artisan db:seed && apache2-foreground
<% end %>
<% if %w[nodejs2 nodejs].include?(@schema['@backend']) %>
FROM node:20.15.1-alpine
WORKDIR /app
COPY backend/package.json backend/yarn.lock ./
RUN yarn install --pure-lockfile
COPY backend .
<% if @schema['@backend'] == 'nodejs2' %>
RUN yarn build
<% end %>
COPY --from=builder /app/build /app/public
CMD ["yarn", "start"]
<% end %>
<% if @schema['@backend'] == 'no-backend' %>
FROM nginx:alpine
COPY frontend/nginx.conf /etc/nginx/conf.d/configfile.template
COPY --from=builder /app/build /usr/share/nginx/html
ENV PORT 8080
ENV HOST 0.0.0.0
EXPOSE 8080
CMD sh -c "envsubst '\$PORT' < /etc/nginx/conf.d/configfile.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
<% end %>