From 4981dcb9197c3b3229fcafff4597afacb17cb2a8 Mon Sep 17 00:00:00 2001 From: Sprait Date: Mon, 4 Sep 2023 19:24:13 +0300 Subject: [PATCH] Multi-platform build (#234) * add multi-platform build --- .github/workflows/publish-latest.yaml | 29 ++++++++++++++++----------- .github/workflows/publish-tag.yaml | 29 ++++++++++++++++----------- Dockerfile | 9 ++++++--- Dockerfile.openvpn | 6 ++++-- main.go | 3 --- 5 files changed, 44 insertions(+), 32 deletions(-) diff --git a/.github/workflows/publish-latest.yaml b/.github/workflows/publish-latest.yaml index ff592ba..33cd3cc 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..222b30f 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 diff --git a/main.go b/main.go index 97f9fa1..fb7e44e 100644 --- a/main.go +++ b/main.go @@ -94,9 +94,6 @@ var logFormats = map[string]log.Formatter{ "json": &log.JSONFormatter{}, } -var ( -) - var ( ovpnServerCertExpire = prometheus.NewGauge(prometheus.GaugeOpts{ Name: "ovpn_server_cert_expire",