Skip to content

Commit

Permalink
Attempt fix dockerfile and add image to serverless config
Browse files Browse the repository at this point in the history
  • Loading branch information
aurora-dot committed May 10, 2024
1 parent 6d648a3 commit 289bc46
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 68 deletions.
33 changes: 18 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
FROM public.ecr.aws/lambda/go:1 as lambda

# Copy over go source code
COPY scraper/main.go /src/main.go
COPY go.mod /src/go.mod
COPY go.sum /src/go.sum
FROM golang:1.22 AS builder

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 main.go
COPY go.mod go.mod
COPY go.sum go.sum

RUN GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -o app main.go

FROM public.ecr.aws/lambda/go:1

# Build go lambda function
RUN GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -o ${LAMBDA_TASK_ROOT} /src/main.go
RUN yum install curl unzip

# Install chrome
RUN mkdir -p /opt/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 yum install xz atk at-spi2-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 over go source code
COPY --from=builder /src/app /var/task/

CMD [ "app" ]
62 changes: 9 additions & 53 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,62 +71,18 @@ functions:
- httpApi:
path: /world
method: get
scrape:
scrapeLocal:
timeout: 30
handler: bin/scraper
events:
- httpApi:
path: /scrape
method: post
# The following are a few example events you can configure
# NOTE: Please make sure to change your handler code to work with those events
# Check the event documentation for details
# events:
# events:
# - httpApi:
# path: /users/create
# method: get
# - websocket: $connect
# - s3: ${env:BUCKET}
# - schedule: rate(10 minutes)
# - sns: greeter-topic
# - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000
# - alexaSkill: amzn1.ask.skill.xx-xx-xx-xx
# - alexaSmartHome: amzn1.ask.skill.xx-xx-xx-xx
# - iot:
# sql: "SELECT * FROM 'some_topic'"
# - cloudwatchEvent:
# event:
# source:
# - "aws.ec2"
# detail-type:
# - "EC2 Instance State-change Notification"
# detail:
# state:
# - pending
# - cloudwatchLog: '/aws/lambda/hello'
# - cognitoUserPool:
# pool: MyUserPool
# trigger: PreSignUp
# - alb:
# listenerArn: arn:aws:elasticloadbalancing:us-east-1:XXXXXX:listener/app/my-load-balancer/50dc6c495c0c9188/
# priority: 1
# conditions:
# host: example.com
# path: /hello

# Define function environment variables here
# environment:
# variable2: value2

# you can add CloudFormation resource templates here
#resources:
# Resources:
# NewResource:
# Type: AWS::S3::Bucket
# Properties:
# BucketName: my-new-bucket
# Outputs:
# NewOutput:
# Description: "Description for the output"
# Value: "Some output value"
scrape:
timeout: 30
memorySize: 2048
image: auroradot/watcher-browser-service:latest
events:
- httpApi:
path: /scrape
method: post

0 comments on commit 289bc46

Please sign in to comment.