From d9cb8486b1ef84693ac576dfc95c2e553e715a8a Mon Sep 17 00:00:00 2001 From: BaoXuebin Date: Tue, 18 Jan 2022 23:25:51 +0800 Subject: [PATCH] update dockerfile: add multi-arch and multi-stage --- .github/workflows/docker.yml | 17 ++++++++++++++--- dockerfile | 17 +++++++++++------ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 939f0f5..4b34cb3 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -7,15 +7,26 @@ jobs: name: Push Docker image to Docker Hub runs-on: ubuntu-latest steps: - - name: Check out the repo + - + name: Check out the repo uses: actions/checkout@v2 - - name: Log in to Docker Hub + - + name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - + name: Login to DockerHub uses: docker/login-action@v1 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - - name: Push to Docker Hub + - + name: Build and push uses: docker/build-push-action@v2 with: + context: . + platforms: linux/amd64,linux/arm64 push: true tags: xdbin/beancount-gs:latest \ No newline at end of file diff --git a/dockerfile b/dockerfile index d36815f..b70b913 100644 --- a/dockerfile +++ b/dockerfile @@ -1,18 +1,23 @@ # syntax=docker/dockerfile:1 -FROM golang:1.17.3 +FROM golang:1.17.3 AS builder ENV GO111MODULE=on \ GOPROXY=https://goproxy.cn,direct \ GIN_MODE=release \ PORT=80 -# install beancount -RUN apt-get update || : && apt-get install python3.5 python3-pip -y -RUN pip3 install beancount -i https://pypi.tuna.tsinghua.edu.cn/simple - -WORKDIR /app +WORKDIR /builder COPY . . COPY public/icons ./public/default_icons RUN go build . +FROM python:latest +RUN pip3 install beancount -i https://pypi.tuna.tsinghua.edu.cn/simple + +WORKDIR /app +COPY --from=builder ./builder/public ./public +COPY --from=builder ./builder/config ./config +COPY --from=builder ./builder/template ./template +COPY --from=builder ./builder/beancount-gs* ./ + EXPOSE 80 \ No newline at end of file