-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
77 lines (64 loc) · 2.01 KB
/
Dockerfile
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
# Use an official Golang runtime as a parent image
FROM golang:1.22 AS build
# Set the working directory in the container
WORKDIR /go/src/app
# Copy the current directory contents into the container
COPY . .
# Build the Go app
RUN make build
# Start a new stage from scratch
FROM debian:bookworm-slim
# Install PostgreSQL client and dependencies for Chrome
RUN apt-get update && \
apt-get install -y \
wget \
gnupg \
ca-certificates \
fonts-liberation \
libappindicator3-1 \
libasound2 \
libatk-bridge2.0-0 \
libatk1.0-0 \
libcups2 \
libdbus-1-3 \
libgdk-pixbuf2.0-0 \
libnspr4 \
libnss3 \
libx11-xcb1 \
libxcomposite1 \
libxdamage1 \
libxrandr2 \
xdg-utils \
libxss1 \
libxtst6 \
unzip \
--no-install-recommends && \
rm -rf /var/lib/apt/lists/*
# Use ARG to define the architecture dynamically at build time
ARG TARGETARCH
# Install Google Chrome or Chromium based on architecture
RUN if [ "$TARGETARCH" = "amd64" ]; then \
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list && \
apt-get update && apt-get install -y google-chrome-stable; \
elif [ "$TARGETARCH" = "arm64" ]; then \
apt-get update && apt-get install -y chromium; \
else \
echo "Unsupported architecture"; \
exit 1; \
fi
# Set Chrome/Chromium as the headless browser for ChromeDP based on architecture
ENV CHROME_PATH=/usr/bin/google-chrome
RUN if [ "$TARGETARCH" = "arm64" ]; then \
export CHROME_PATH=/usr/bin/chromium; \
fi
# Set the working directory in the container
WORKDIR /app
# Copy the built executable from the previous stage
COPY --from=build /go/src/app/scraper .
COPY --from=build /go/src/app/api .
COPY --from=build /go/src/app/mailer .
COPY scripts/wait-for-it.sh /wait-for-it.sh
RUN chmod +x /wait-for-it.sh
# Run the Go app
CMD ["./scraper"]