Skip to content

Commit

Permalink
fix: dynamic worker version (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Apr 4, 2021
1 parent a71eb4e commit cd0dd17
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Expand Up @@ -29,7 +29,7 @@ jobs:
version="$(bash .github/workflows/determine_docker_image_tag.sh)"
bash k8/generate.sh $version
env:
WORKER_COUNT: 2
WORKER_COUNT: 1
- run: kubectl apply -f k8/
- name: Run e2e tests
working-directory: e2e
Expand All @@ -40,7 +40,7 @@ jobs:
echo "Host: $FRONTEND_URL"
npx wait-on "$FRONTEND_URL/service/control/health"
kubectl wait --timeout 5m --for=condition=ready pod -l role=worker
ROOT_TEST_URL=$FRONTEND_URL npm run test
ROOT_TEST_URL=$FRONTEND_URL npm run test -- --forbid-only --retries 2
- name: Setup tmate session
if: ${{ failure() }}
uses: mxschmitt/action-tmate@v3
Expand Down
2 changes: 1 addition & 1 deletion e2e/package.json
Expand Up @@ -2,7 +2,7 @@
"name": "try-playwright",
"version": "1.0.0",
"scripts": {
"test": "folio -j 1 --retries 2 --reporter list"
"test": "folio -j 1 --reporter list"
},
"repository": {
"type": "git",
Expand Down
12 changes: 8 additions & 4 deletions e2e/tests/api.spec.ts
Expand Up @@ -15,6 +15,10 @@ function executeCode(code: string, language: string): Promise<Response> {
})
}

function expectValidVersion(payload: any) {
expect(payload.version).toMatch(/^\d+.\d+.\d+$/)
}

describe("JavaScript", () => {
it("can execute basic code", async () => {
const code = `console.log(1 + 1)`
Expand All @@ -23,7 +27,7 @@ describe("JavaScript", () => {
const body = await resp.json()
expect(body).toHaveProperty('success', true)
expect(body).toHaveProperty('error', '')
expect(body).toHaveProperty('version', '') // TODO: add version
expectValidVersion(body)
expect(body).toHaveProperty('files', [])
expect(body).toHaveProperty('output', '2')
})
Expand All @@ -36,7 +40,7 @@ describe("Python", () => {
const body = await resp.json()
expect(body).toHaveProperty('success', true)
expect(body).toHaveProperty('error', '')
expect(body).toHaveProperty('version', '') // TODO: add version
expectValidVersion(body)
expect(body).toHaveProperty('files', [])
expect(body).toHaveProperty('output', '2')
})
Expand All @@ -58,7 +62,7 @@ public class Example {
const body = await resp.json()
expect(body).toHaveProperty('success', true)
expect(body).toHaveProperty('error', '')
expect(body).toHaveProperty('version', '') // TODO: add version
expectValidVersion(body)
expect(body).toHaveProperty('files', [])
expect(body).toHaveProperty('output', '2')
})
Expand All @@ -84,7 +88,7 @@ namespace e2e
const body = await resp.json()
expect(body).toHaveProperty('success', true)
expect(body).toHaveProperty('error', '')
expect(body).toHaveProperty('version', '') // TODO: add version
expectValidVersion(body)
expect(body).toHaveProperty('files', [])
expect(body).toHaveProperty('output', '2')
})
Expand Down
2 changes: 1 addition & 1 deletion internal/worker/worker.go
Expand Up @@ -107,7 +107,7 @@ func (w *Worker) consumeMessage(incomingMessages <-chan amqp.Delivery) error {
if err := json.Unmarshal(incomingMessage.Body, &incomingMessageParsed); err != nil {
return fmt.Errorf("could not parse incoming amqp message: %w", err)
}
outgoingMessage := &workertypes.WorkerResponsePayload{}
outgoingMessage := &workertypes.WorkerResponsePayload{Version: os.Getenv("PLAYWRIGHT_VERSION")}
if err := w.options.Handler(w, incomingMessageParsed.Code); err != nil {
outgoingMessage.Success = false
outgoingMessage.Error = err.Error()
Expand Down
8 changes: 6 additions & 2 deletions worker-csharp/Dockerfile
@@ -1,3 +1,4 @@
ARG PLAYWRIGHT_VERSION=1.9.2
FROM golang:1.16-buster as builder
WORKDIR /root
COPY go.mod /root/
Expand All @@ -8,7 +9,10 @@ COPY worker-csharp/main.go /root/
COPY internal/ /root/internal/
RUN CGO_ENABLED=0 GOOS=linux go build -o /app

FROM mcr.microsoft.com/playwright:v1.10.0-focal
FROM mcr.microsoft.com/playwright:v${PLAYWRIGHT_VERSION}-focal

ARG PLAYWRIGHT_VERSION
ENV PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION

RUN curl -o packages-microsoft-prod.deb https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb && \
dpkg -i packages-microsoft-prod.deb && \
Expand All @@ -27,7 +31,7 @@ USER pwuser
RUN mkdir /home/pwuser/project/ && \
cd /home/pwuser/project/ && \
dotnet new console && \
dotnet add package PlaywrightSharp && \
dotnet add package PlaywrightSharp --version 0.192.0 && \
dotnet build && \
bin/Debug/net5.0/.playwright/unix/native/playwright.sh install && \
rm Program.cs
Expand Down
9 changes: 7 additions & 2 deletions worker-java/Dockerfile
@@ -1,3 +1,4 @@
ARG PLAYWRIGHT_VERSION=1.10.0
FROM golang:1.16-buster as builder
WORKDIR /root
COPY go.mod /root/
Expand All @@ -8,13 +9,17 @@ COPY worker-java/main.go /root/
COPY internal/ /root/internal/
RUN CGO_ENABLED=0 GOOS=linux go build -o /app

FROM mcr.microsoft.com/playwright/java:focal
FROM mcr.microsoft.com/playwright/java:focal-v$PLAYWRIGHT_VERSION

RUN apt-get remove -y openjdk-11-jdk && \
apt-get install -y openjdk-14-jdk

ENV JAVA_HOME=/usr/lib/jvm/java-14-openjdk-amd64
RUN apt-get remove -y python3.8 python3-pip git ssh xvfb curl nodejs && \
apt-get autoremove -y

ENV JAVA_HOME=/usr/lib/jvm/java-14-openjdk-amd64
ARG PLAYWRIGHT_VERSION
ENV PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION

RUN adduser pwuser
USER pwuser
Expand Down
2 changes: 1 addition & 1 deletion worker-java/pom.xml
Expand Up @@ -14,7 +14,7 @@
<dependency>
<groupId>com.microsoft.playwright</groupId>
<artifactId>playwright</artifactId>
<version>1.10.0</version>
<version>${env.PLAYWRIGHT_VERSION}</version>
</dependency>
</dependencies>
<build>
Expand Down
8 changes: 6 additions & 2 deletions worker-javascript/Dockerfile
@@ -1,3 +1,4 @@
ARG PLAYWRIGHT_VERSION=1.10.0
FROM golang:1.16-buster as builder
WORKDIR /root
COPY go.mod /root/
Expand All @@ -8,14 +9,17 @@ COPY worker-javascript/main.go /root/
COPY internal/ /root/internal/
RUN CGO_ENABLED=0 GOOS=linux go build -o /app

FROM mcr.microsoft.com/playwright:v1.10.0-focal
FROM mcr.microsoft.com/playwright:v${PLAYWRIGHT_VERSION}-focal

ARG PLAYWRIGHT_VERSION
ENV PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION

RUN apt-get remove -y python3.8 python3-pip git ssh xvfb curl && \
apt-get autoremove -y

WORKDIR /home/pwuser/

RUN npm install -g playwright@1.10
RUN npm install -g playwright@${PLAYWRIGHT_VERSION}

USER pwuser

Expand Down
8 changes: 6 additions & 2 deletions worker-python/Dockerfile
@@ -1,3 +1,4 @@
ARG PLAYWRIGHT_VERSION=1.10.0
FROM golang:1.16-buster as builder
WORKDIR /root
COPY go.mod /root/
Expand All @@ -8,14 +9,17 @@ COPY worker-python/main.go /root/
COPY internal/ /root/internal/
RUN CGO_ENABLED=0 GOOS=linux go build -o /app

FROM mcr.microsoft.com/playwright:v1.10.0-focal
FROM mcr.microsoft.com/playwright:v${PLAYWRIGHT_VERSION}-focal

ARG PLAYWRIGHT_VERSION
ENV PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION

RUN apt-get remove -y git ssh xvfb curl && \
apt-get autoremove -y

WORKDIR /home/pwuser/

RUN pip install playwright==1.10.0
RUN pip install playwright==${PLAYWRIGHT_VERSION}

USER pwuser

Expand Down

0 comments on commit cd0dd17

Please sign in to comment.