-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix dockerfile and add image to serverless config (#3)
* Attempt fix dockerfile and add image to serverless config * Run only using one image * WIP * remove unneeded code * WIP * WIP * Get Dockerfile to work and run locally * Get chrome to work within Docker * Update GitHub Action * Add finishing touches
- Loading branch information
1 parent
6d648a3
commit 50cd6af
Showing
14 changed files
with
131 additions
and
1,455 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CHROME_PATH=/usr/bin/google-chrome-stable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,20 +31,7 @@ jobs: | |
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v5 | ||
with: | ||
go-version: ${{ env.GO_VERSION }} | ||
cache: true | ||
- uses: Jerome1337/[email protected] | ||
|
||
# build: | ||
# runs-on: ubuntu-latest | ||
# steps: | ||
# - uses: actions/checkout@v3 | ||
|
||
# - name: Set up Go | ||
# uses: actions/setup-go@v5 | ||
# with: | ||
# go-version: ${{ env.GO_VERSION }} | ||
|
||
# - name: Build | ||
# run: go build -v ./... | ||
|
||
# - name: Test | ||
# run: go test -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,6 @@ node_modules | |
|
||
# Ignore build directory | ||
bin | ||
|
||
.aws-lambda-rie | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,64 @@ | ||
FROM public.ecr.aws/lambda/go:1 as lambda | ||
FROM ubuntu:20.04 | ||
|
||
# Copy over go source code | ||
COPY scraper/main.go /src/main.go | ||
COPY go.mod /src/go.mod | ||
COPY go.sum /src/go.sum | ||
USER root | ||
|
||
ARG DEBIAN_FRONTEND=noninteractive | ||
ARG TZ=Europe/London | ||
|
||
ENV TZ=$TZ | ||
ENV DEBIAN_FRONTEND=$DEBIAN_FRONTEND | ||
ENV LANG="C.UTF-8" | ||
ENV DEBUG_COLORS=true | ||
ENV CHROME_PATH=/src/chrome/chrome | ||
|
||
RUN apt-get update && apt-get install -y \ | ||
ca-certificates \ | ||
curl \ | ||
dumb-init \ | ||
git \ | ||
gnupg \ | ||
libu2f-udev \ | ||
software-properties-common \ | ||
ssh \ | ||
wget \ | ||
xvfb | ||
|
||
RUN apt-get install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 libnss3-dev lsb-release xdg-utils libgbm-dev | ||
|
||
RUN apt install golang-go -y | ||
|
||
WORKDIR /src | ||
|
||
# Install packages | ||
RUN yum install go xz atk cups-libs gtk3 libXcomposite alsa-lib tar \ | ||
libXcursor libXdamage libXext libXi libXrandr libXScrnSaver \ | ||
libXtst pango at-spi2-atk libXt xorg-x11-server-Xvfb \ | ||
xorg-x11-xauth dbus-glib dbus-glib-devel unzip bzip2 -y -q | ||
COPY scraper/main.go go.mod go.sum ./ | ||
|
||
RUN GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -o app main.go && \ | ||
rm main.go go.mod go.sum | ||
|
||
RUN echo "ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true" | debconf-set-selections && \ | ||
apt-get -y -qq install software-properties-common &&\ | ||
apt-add-repository "deb http://archive.canonical.com/ubuntu $(lsb_release -sc) partner" && \ | ||
apt-get -y -qq --no-install-recommends install \ | ||
fontconfig \ | ||
fonts-freefont-ttf \ | ||
fonts-gfs-neohellenic \ | ||
fonts-indic \ | ||
fonts-ipafont-gothic \ | ||
fonts-kacst \ | ||
fonts-liberation \ | ||
fonts-noto-cjk \ | ||
fonts-noto-color-emoji \ | ||
fonts-roboto \ | ||
fonts-thai-tlwg \ | ||
fonts-ubuntu \ | ||
fonts-wqy-zenhei | ||
|
||
RUN apt install curl unzip -y | ||
|
||
# Build go lambda function | ||
RUN GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -o ${LAMBDA_TASK_ROOT} /src/main.go | ||
RUN mkdir -p "/src/chrome/" \ | ||
&& curl -Lo "/src/chrome/chrome-linux.zip" "https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F1299153%2Fchrome-linux.zip?generation=1715336417866122&alt=media" \ | ||
&& unzip -q "/src/chrome/chrome-linux.zip" -d "/src/chrome/" && mv /src/chrome/chrome-linux/* /src/chrome/ \ | ||
&& rm -rf /src/chrome/chrome-linux "/src/chrome/chrome-linux.zip" | ||
|
||
# Install chrome | ||
RUN mkdir -p /opt/chrome/ | ||
RUN curl -Lo "/opt/chrome/chrome-linux.zip" "https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F1299153%2Fchrome-linux.zip?generation=1715336417866122&alt=media" | ||
RUN unzip -q "/opt/chrome/chrome-linux.zip" -d "/opt/chrome/" | ||
RUN mv /opt/chrome/chrome-linux/* /opt/chrome/ | ||
RUN rm -rf /opt/chrome/chrome-linux "/opt/chrome/chrome-linux.zip" | ||
RUN echo CHROME_PATH=${CHROME_PATH} > .env | ||
|
||
CMD [ "app" ] | ||
ENTRYPOINT [ "src/app" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
.PHONY: install build debugBuild clean deploy | ||
.PHONY: clean install build buildDocker runDebug runDebugDocker getDebugTools deploy | ||
|
||
clean: | ||
rm -rf ./node_modules | ||
|
||
install: | ||
npm i | ||
|
||
getDebugTools: | ||
wget https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie | ||
mkdir -p .aws-lambda-rie | ||
mv aws-lambda-rie .aws-lambda-rie/aws-lambda-rie | ||
chmod +x .aws-lambda-rie/aws-lambda-rie | ||
|
||
build: | ||
env GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -o bin/hello hello/main.go | ||
env GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -o bin/world world/main.go | ||
env GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -o bin/scraper scraper/main.go | ||
GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -o bin/scraper scraper/main.go | ||
|
||
debugBuild: | ||
env GOARCH=amd64 GOOS=linux go build -v -gcflags='all=-N -l' -ldflags="-s -w" -o bin/hello hello/main.go | ||
env GOARCH=amd64 GOOS=linux go build -v -gcflags='all=-N -l' -ldflags="-s -w" -o bin/world world/main.go | ||
debug: | ||
env GOARCH=amd64 GOOS=linux go build -v -gcflags='all=-N -l' -ldflags="-s -w" -o bin/scraper scraper/main.go | ||
|
||
debugDeploy: clean install debugBuild | ||
env SLS_DEBUG=* npx sls offline --useDocker | ||
runDebug: debug | ||
~/.aws-lambda-rie/aws-lambda-rie ./bin/scraper | ||
|
||
clean: | ||
rm -rf ./node_modules | ||
rm -rf ./bin | ||
buildDocker: | ||
docker build -t watcher-local-build . | ||
|
||
runDebugDocker: buildDocker | ||
docker run --platform linux/amd64 -v ./.aws-lambda-rie:/aws-lambda -p 9000:8080 --entrypoint /aws-lambda/aws-lambda-rie watcher-local-build /src/app | ||
|
||
deploy: clean install build | ||
deploy: install | ||
npx sls deploy --verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.