From fd92e43de8679e9bee5187397c01867338e5d23e Mon Sep 17 00:00:00 2001 From: Sprait Date: Mon, 28 Aug 2023 20:55:48 +0300 Subject: [PATCH] multi-platform build --- .github/workflows/publish-latest.yaml | 29 ++++++++++++++++----------- .github/workflows/publish-tag.yaml | 29 ++++++++++++++++----------- Dockerfile | 9 ++++++--- Dockerfile.openvpn | 6 ++++-- 4 files changed, 44 insertions(+), 29 deletions(-) diff --git a/.github/workflows/publish-latest.yaml b/.github/workflows/publish-latest.yaml index ff592ba..167db51 100644 --- a/.github/workflows/publish-latest.yaml +++ b/.github/workflows/publish-latest.yaml @@ -12,19 +12,24 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 0 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASS }} - name: Push openvpn image to Docker Hub - uses: docker/build-push-action@v1 + uses: docker/build-push-action@v4 with: - username: ${{ secrets.DOCKER_USER }} - password: ${{ secrets.DOCKER_PASS }} - repository: flant/ovpn-admin - tags: openvpn-latest - dockerfile: Dockerfile.openvpn + tags: flant/ovpn-admin:openvpn-latest + platforms: linux/amd64,linux/arm64,linux/arm,linux/386 + file: Dockerfile.openvpn + push: true - name: Push ovpn-admin image to Docker Hub - uses: docker/build-push-action@v1 + uses: docker/build-push-action@v4 with: - username: ${{ secrets.DOCKER_USER }} - password: ${{ secrets.DOCKER_PASS }} - repository: flant/ovpn-admin - tags: latest - dockerfile: Dockerfile + tags: flant/ovpn-admin:latest + platforms: linux/amd64,linux/arm64,linux/arm,linux/386 + file: Dockerfile + push: true \ No newline at end of file diff --git a/.github/workflows/publish-tag.yaml b/.github/workflows/publish-tag.yaml index 05eb739..5320fb3 100644 --- a/.github/workflows/publish-tag.yaml +++ b/.github/workflows/publish-tag.yaml @@ -16,19 +16,24 @@ jobs: - name: Get the version id: get_version run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASS }} - name: Push openvpn image to Docker Hub - uses: docker/build-push-action@v1 + uses: docker/build-push-action@v4 with: - username: ${{ secrets.DOCKER_USER }} - password: ${{ secrets.DOCKER_PASS }} - repository: flant/ovpn-admin - tags: openvpn-${{ steps.get_version.outputs.VERSION }} - dockerfile: Dockerfile.openvpn + tags: flant/ovpn-admin:openvpn-${{ steps.get_version.outputs.VERSION }} + platforms: linux/amd64,linux/arm64,linux/arm,linux/386 + file: Dockerfile.openvpn + push: true - name: Push ovpn-admin image to Docker Hub - uses: docker/build-push-action@v1 + uses: docker/build-push-action@v4 with: - username: ${{ secrets.DOCKER_USER }} - password: ${{ secrets.DOCKER_PASS }} - repository: flant/ovpn-admin - tags: ${{ steps.get_version.outputs.VERSION }} - dockerfile: Dockerfile + tags: flant/ovpn-admin:${{ steps.get_version.outputs.VERSION }} + platforms: linux/amd64,linux/arm64,linux/arm,linux/386 + file: Dockerfile + push: true \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 42ff620..aac416c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,20 @@ FROM node:16-alpine3.15 AS frontend-builder COPY frontend/ /app -RUN cd /app && npm install && npm run build +RUN apk add --update python3 make g++ && cd /app && npm install && npm run build FROM golang:1.17.3-buster AS backend-builder RUN go install github.com/gobuffalo/packr/v2/packr2@latest COPY --from=frontend-builder /app/static /app/frontend/static COPY . /app -RUN cd /app && packr2 && env CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -a -tags netgo -ldflags '-linkmode external -extldflags -static -s -w' -o ovpn-admin && packr2 clean +ARG TARGETARCH +RUN cd /app && packr2 && env CGO_ENABLED=1 GOOS=linux GOARCH=${TARGETARCH} go build -a -tags netgo -ldflags '-linkmode external -extldflags -static -s -w' -o ovpn-admin && packr2 clean FROM alpine:3.16 WORKDIR /app COPY --from=backend-builder /app/ovpn-admin /app +ARG TARGETARCH RUN apk add --update bash easy-rsa openssl openvpn coreutils && \ ln -s /usr/share/easy-rsa/easyrsa /usr/local/bin && \ - wget https://github.com/pashcovich/openvpn-user/releases/download/v1.0.4/openvpn-user-linux-amd64.tar.gz -O - | tar xz -C /usr/local/bin && \ + wget https://github.com/pashcovich/openvpn-user/releases/download/v1.0.4/openvpn-user-linux-${TARGETARCH}.tar.gz -O - | tar xz -C /usr/local/bin && \ rm -rf /tmp/* /var/tmp/* /var/cache/apk/* /var/cache/distfiles/* +RUN if [ -f "/usr/local/bin/openvpn-user-${TARGETARCH}" ]; then ln -s /usr/local/bin/openvpn-user-${TARGETARCH} /usr/local/bin/openvpn-user; fi \ No newline at end of file diff --git a/Dockerfile.openvpn b/Dockerfile.openvpn index ce80f40..12ddf94 100644 --- a/Dockerfile.openvpn +++ b/Dockerfile.openvpn @@ -1,7 +1,9 @@ FROM alpine:3.16 +ARG TARGETARCH RUN apk add --update bash openvpn easy-rsa iptables && \ ln -s /usr/share/easy-rsa/easyrsa /usr/local/bin && \ - wget https://github.com/pashcovich/openvpn-user/releases/download/v1.0.4/openvpn-user-linux-amd64.tar.gz -O - | tar xz -C /usr/local/bin && \ + wget https://github.com/pashcovich/openvpn-user/releases/download/v1.0.4/openvpn-user-linux-${TARGETARCH}.tar.gz -O - | tar xz -C /usr/local/bin && \ rm -rf /tmp/* /var/tmp/* /var/cache/apk/* /var/cache/distfiles/* +RUN if [ -f "/usr/local/bin/openvpn-user-${TARGETARCH}" ]; then ln -s /usr/local/bin/openvpn-user-${TARGETARCH} /usr/local/bin/openvpn-user; fi COPY setup/ /etc/openvpn/setup -RUN chmod +x /etc/openvpn/setup/configure.sh +RUN chmod +x /etc/openvpn/setup/configure.sh \ No newline at end of file