This commit is contained in:
Dmytro Bondar 2023-10-25 13:25:06 +00:00 committed by GitHub
commit 41b7f7d688
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 79 additions and 65 deletions

5
.dockerignore Normal file
View File

@ -0,0 +1,5 @@
.git
.github
README.md
ui/node_modules
wireguard

View File

@ -5,7 +5,16 @@

version: 2
updates:
- package-ecosystem: "" # See documentation for possible values
directory: "/" # Location of package manifests
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: "weekly"
interval: 'weekly'
groups:
github-actions:
patterns:
- '*'

- package-ecosystem: 'gomod'
directory: '/'
schedule:
interval: 'weekly'

View File

@ -1,4 +1,4 @@
name: Build multi-platform docker images via buildx
name: Docker Build

on:
pull_request:
@ -10,58 +10,50 @@ on:
tags:
- 'v*.*.*'

env:
IMAGE_NAME: ${{ vars.IMAGE_NAME || github.repository }}
IMAGE_PLATFORMS: ${{ vars.IMAGE_PLATFORMS || 'linux/amd64,linux/arm64,linux/arm/v7' }}
REGISTRY: ${{ vars.REGISTRY_NAME || secrets.REGISTRY_NAME || 'docker.io' }}

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set Prepare
id: prep
run: |
DOCKER_IMAGE=vx3r/wg-gen-web
VERSION=edge
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
elif [[ $GITHUB_REF == refs/pull/* ]]; then
VERSION=pr-${{ github.event.number }}
fi
TAGS="${DOCKER_IMAGE}:${VERSION}"
if [ "${{ github.event_name }}" = "push" ]; then
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
fi
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
echo ::set-output name=version::${VERSION}
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
echo ::set-output name=sha_short::$(git rev-parse --short HEAD)
-
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
# https://github.com/actions/checkout
- uses: actions/checkout@v4

# https://github.com/docker/login-action
- uses: docker/login-action@v3
if: ${{ github.event_name != 'pull_request' }}
with:
username: ${{ secrets.DOCKER_LOGIN_USERNAME }}
password: ${{ secrets.DOCKER_LOGIN_PASSWORD }}
-
name: Build and push
uses: docker/build-push-action@v2
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_LOGIN_USERNAME || secrets.REGISTRY_USERNAME || github.actor }}
password: ${{ secrets.DOCKER_LOGIN_PASSWORD || secrets.REGISTRY_PASSWORD || github.token }}

# https://github.com/docker/setup-buildx-action
- uses: docker/setup-buildx-action@v3

# https://github.com/docker/setup-qemu-action
- uses: docker/setup-qemu-action@v3

# https://github.com/docker/metadata-action
- uses: docker/metadata-action@v5
id: meta
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=raw,value=latest,enable={{is_default_branch}}
type=sha

# https://github.com/docker/build-push-action
- uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7
platforms: ${{ env.IMAGE_PLATFORMS }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
labels: |
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
build-args: |
COMMIT=${{ steps.prep.outputs.sha_short }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: COMMIT=${{ github.sha }}

View File

@ -1,25 +1,33 @@
### Back-End
FROM --platform=${BUILDPLATFORM} golang:alpine AS build-back
ENV CGO_ENABLED=0
WORKDIR /app
ARG COMMIT="N/A"
RUN --mount=type=bind,source=go.sum,target=go.sum \
--mount=type=bind,source=go.mod,target=go.mod \
--mount=type=cache,target=/go/pkg \
go mod download
ARG TARGETARCH TARGETOS
RUN --mount=type=bind,target=. \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
GOARCH=${TARGETARCH} GOOS=${TARGETOS} go build -o /out/wg-gen-web -ldflags "-w -s -X 'github.com/vx3r/wg-gen-web/version.Version=${COMMIT::7}'" ./cmd/wg-gen-web

FROM golang:alpine AS build-back
### Front-End
FROM --platform=${BUILDPLATFORM} node:18-alpine AS build-front
WORKDIR /app
ARG COMMIT
COPY . .
RUN go build -o wg-gen-web-linux -ldflags="-X 'github.com/vx3r/wg-gen-web/version.Version=${COMMIT}'" github.com/vx3r/wg-gen-web/cmd/wg-gen-web

FROM node:18.13.0-alpine AS build-front
WORKDIR /app
COPY ui/package*.json ./
RUN npm install
COPY ui/package.json ui/package-lock.json ./
RUN npm ci --no-fund
COPY ui/ ./
RUN npm run build

FROM alpine
RUN apk add -U --no-cache ca-certificates
WORKDIR /app
COPY --from=build-back /app/wg-gen-web-linux .
COPY --from=build-front /app/dist ./ui/dist
COPY .env .
RUN chmod +x ./wg-gen-web-linux
RUN apk add --no-cache ca-certificates
COPY --from=build-back /out/wg-gen-web .
COPY --from=build-front /app/dist ./ui/dist
RUN chmod +x ./wg-gen-web
EXPOSE 8080

CMD ["/app/wg-gen-web-linux"]
CMD ["/app/wg-gen-web"]