Skip to content

Commit

Permalink
Multi arch and refactoring (#2579)
Browse files Browse the repository at this point in the history
* add multi arch

* use node 20 and remove got from cron script
  • Loading branch information
siutsin authored Dec 26, 2023
1 parent f81dc0f commit f133b7a
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 419 deletions.
18 changes: 13 additions & 5 deletions .github/workflows/build-image-jung2bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
registry: ghcr.io
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -33,10 +40,11 @@ jobs:
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v2
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 18.x ]
node-version: [ 20.x ]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nodejs 18.19.0
nodejs 20.10.0
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM node:18 AS build-env
FROM node:20 AS build-env
ADD . /app
WORKDIR /app
RUN npm i
RUN npm run build

FROM gcr.io/distroless/nodejs:18
FROM gcr.io/distroless/nodejs:20
COPY --from=build-env /app/dist /dist
WORKDIR /dist
ENV DOCKER=true
Expand Down
4 changes: 2 additions & 2 deletions cron/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM node:16 AS build-env
FROM node:20 AS build-env
ADD . /app
WORKDIR /app
RUN npm i

FROM gcr.io/distroless/nodejs:16
FROM gcr.io/distroless/nodejs:20
COPY --from=build-env /app /app
WORKDIR /app
CMD ["index.js"]
33 changes: 22 additions & 11 deletions cron/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import got from 'got'

const main = async () => {
const current = new Date()
const min = current.getMinutes()
Expand All @@ -9,15 +7,28 @@ const main = async () => {
current.setMinutes(min - remainder)

const timeString = current.toISOString()
const { request, headers, body } = await got(process.env.OFF_FROM_WORK_URL, {
retry: { limit: 0 },
searchParams: { timeString }
})
console.log({
requestUrl: request.requestUrl.toJSON(),
responseHeaders: headers,
responseBody: JSON.parse(body)
})
const url = new URL(process.env.OFF_FROM_WORK_URL)
url.searchParams.append('timeString', timeString)

try {
const response = await fetch(url, {
method: 'GET'
})

if (!response.ok) {
console.error(`HTTP error! status: ${response.status}`)
return
}

const responseBody = await response.json()
console.log({
requestUrl: url.toString(),
responseHeaders: response.headers,
responseBody
})
} catch (e) {
console.error(e.toLocaleString())
}
}

main().catch(e => console.error(e.toLocaleString()))
Loading

0 comments on commit f133b7a

Please sign in to comment.