1
1
Fork 0
mirror of https://github.com/vx3r/wg-gen-web.git synced 2024-05-08 23:16:02 +02:00

Compare commits

...

2 Commits

Author SHA1 Message Date
Dmytro Bondar cafa72d864
Refactor Dockerfile
- Add stages for better layer caching
- Re-order layers in final image
- add .dockerignore
2023-09-21 13:37:27 +02:00
Dmytro Bondar af7c29f21a
Refactor workflow:
- Replace `prep` step by `docker/metadata-action`
- Use vars and secrets to support customizations for:
      - registry name
      - registry user
      - registry password
      - image name
      - image platforms

Signed-off-by: Dmytro Bondar <git@bonddim.com>
2023-09-20 21:28:21 +02:00
3 changed files with 68 additions and 63 deletions

5
.dockerignore Normal file
View File

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

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@v4
-
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@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Login to DockerHub
uses: docker/login-action@v3
# 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@v5
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 golang:alpine AS go-base
ENV CGO_ENABLED=0
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
FROM go-base AS build-back
ARG COMMIT="N/A"
FROM golang:alpine AS build-back
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
RUN go install -ldflags "-w -s -X 'github.com/vx3r/wg-gen-web/version.Version=${COMMIT::7}'" ./cmd/...
FROM node:18.13.0-alpine AS build-front
### Front-End
FROM node:18-alpine AS node-base
WORKDIR /app
COPY ui/package*.json ./
RUN npm install
COPY ui/ ./
COPY ui/package.json ui/package-lock.json ./
RUN npm ci --no-fund
FROM node-base AS build-front
COPY ui/ .
RUN npm run build
FROM alpine
### Final
FROM alpine AS final-base
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 /go/bin/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"]