From 85188e49ef690f0445de50eb51cde6e2fe95e64d Mon Sep 17 00:00:00 2001 From: zsnmwy <35299017+zsnmwy@users.noreply.github.com> Date: Mon, 29 May 2023 04:36:03 +0800 Subject: [PATCH 1/4] Create docker-image.yml --- .github/workflows/docker-image.yml | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 00000000..57fa807c --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,38 @@ +name: Docker Image CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + + build: + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Docker Login + # You may pin to the exact commit or the version. + # uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a + uses: docker/login-action@v2.1.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ghcr.io/zsnmwy/esm-sh:latest From 79eaf56e438f3179a276228302b1aeb7fa69e3a7 Mon Sep 17 00:00:00 2001 From: zsnmwy <35299017+zsnmwy@users.noreply.github.com> Date: Mon, 29 May 2023 04:45:13 +0800 Subject: [PATCH 2/4] FIX: Docker Image --- .github/workflows/docker-image.yml | 5 ++++- Dockerfile | 32 +++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 57fa807c..84415579 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -6,6 +6,9 @@ on: pull_request: branches: [ "main" ] +permissions: + packages: write + jobs: build: @@ -35,4 +38,4 @@ jobs: context: . platforms: linux/amd64,linux/arm64 push: true - tags: ghcr.io/zsnmwy/esm-sh:latest + tags: ghcr.io/${{ github.repository_owner }}/esmd:latest diff --git a/Dockerfile b/Dockerfile index 9407b091..430fb127 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,28 @@ +# syntax=docker/dockerfile:1 FROM golang:1.18 AS build +WORKDIR /app +COPY . . RUN apt-get update -y && apt-get install -y xz-utils -RUN useradd -u 1000 -m esm -RUN mkdir /esm && chown esm:esm /esm -RUN git clone https://github.com/esm-dev/esm.sh /esm/esm.sh -RUN git checkout v124 +RUN go build -o /esmd -USER esm -WORKDIR /esm -RUN go build -o bin/esmd esm.sh/main.go +FROM node:18-alpine3.16 +ENV USER_ID=65535 +ENV GROUP_ID=65535 +ENV USER_NAME=esm +ENV GROUP_NAME=esm -RUN echo "{\"port\":80,\"workDir\":\"/esm\"}" >> /esm/config.json -ENTRYPOINT ["/esm/bin/esmd", "--config", "config.json"] +RUN apk add --no-cache libc6-compat +RUN addgroup -g $GROUP_ID $GROUP_NAME && \ + adduser --shell /sbin/nologin --disabled-password \ + --uid $USER_ID --ingroup $GROUP_NAME $USER_NAME +RUN mkdir -p /usr/local/lib && chown -R $USER_NAME:$GROUP_NAME /usr/local/lib + +USER $USER_NAME + +WORKDIR /home/esm +COPY --from=build /esmd /home/esm/esmd + +RUN echo "{\"port\":80,\"workDir\":\"/home/esm/workdir\"}" >> /home/esm/config.json + +ENTRYPOINT ["/home/esm/esmd", "--config", "config.json"] From ff62ce89e82ffad39851e5881019259573eba297 Mon Sep 17 00:00:00 2001 From: zsnmwy <35299017+zsnmwy@users.noreply.github.com> Date: Mon, 29 May 2023 13:48:39 +0800 Subject: [PATCH 3/4] Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 430fb127..fbf550e7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ RUN apk add --no-cache libc6-compat RUN addgroup -g $GROUP_ID $GROUP_NAME && \ adduser --shell /sbin/nologin --disabled-password \ --uid $USER_ID --ingroup $GROUP_NAME $USER_NAME -RUN mkdir -p /usr/local/lib && chown -R $USER_NAME:$GROUP_NAME /usr/local/lib +RUN mkdir -p /usr/local/lib && chown -R $USER_NAME:$GROUP_NAME /usr/local USER $USER_NAME From 09f651a6976855a54cdc7613380cd8828b193364 Mon Sep 17 00:00:00 2001 From: zsnmwy <35299017+zsnmwy@users.noreply.github.com> Date: Mon, 29 May 2023 06:14:32 +0000 Subject: [PATCH 4/4] chore: add xz for alpine --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index fbf550e7..fde10398 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ ENV GROUP_ID=65535 ENV USER_NAME=esm ENV GROUP_NAME=esm -RUN apk add --no-cache libc6-compat +RUN apk add --no-cache libc6-compat xz RUN addgroup -g $GROUP_ID $GROUP_NAME && \ adduser --shell /sbin/nologin --disabled-password \ --uid $USER_ID --ingroup $GROUP_NAME $USER_NAME