Skip to content

Commit

Permalink
feat: multi platform docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
Hintay committed Jan 7, 2023
1 parent f69fadc commit 41ced2e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
43 changes: 29 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Get the version
id: get_version
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT

- name: Set up Go
uses: actions/setup-go@v3
with:
Expand All @@ -131,10 +127,12 @@ jobs:
export _NAME=nginx-ui-$(jq ".$GOOS[\"$GOARCH$GOARM\"].name" -r < .github/build/build_info.json)
export _ARCH=$(jq ".$GOOS[\"$GOARCH$GOARM\"].arch" -r < .github/build/build_info.json)
export _ABI=$(jq ".$GOOS[\"$GOARCH$GOARM\"].abi // \"\"" -r < .github/build/build_info.json)
echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, ABI: $_ABI, RELEASE_NAME: $_NAME"
export _ARTIFACT=nginx-ui-$GOOS-$GOARCH$(if [[ "$GOARM" ]]; then echo "v$GOARM"; fi)
echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, ABI: $_ABI, RELEASE_NAME: $_NAME, ARTIFACT_NAME: $_ARTIFACT"
echo "ARCH_NAME=$_ARCH" >> $GITHUB_ENV
echo "ABI=$_ABI" >> $GITHUB_ENV
echo "DIST=$_NAME" >> $GITHUB_ENV
echo "ARTIFACT=$_ARTIFACT" >> $GITHUB_ENV
- name: Install musl cross compiler
if: env.GOOS == 'linux'
Expand Down Expand Up @@ -176,7 +174,7 @@ jobs:
- name: Archive backend artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ env.DIST }}
name: ${{ env.ARTIFACT }}
path: dist/nginx-ui

- name: Prepare publish
Expand All @@ -191,49 +189,66 @@ jobs:
with:
files: ${{ env.DIST }}.tar.gz

docker-build:
runs-on: ubuntu-latest
needs: build
env:
PLATFORMS: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6,linux/arm/v5
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Get the version
id: get_version
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT

- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: ./dist

- name: Prepare Artifacts
run: chmod +x ./dist/nginx-ui-*/nginx-ui

- name: Set up Docker Buildx
if: env.GOOS == 'linux' && env.GOARCH == 'amd64'
id: buildx
uses: docker/setup-buildx-action@v2

- name: Login to DockerHub
if: env.GOOS == 'linux' && env.GOARCH == 'amd64'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Prepare Dockerfile
if: github.event_name == 'release' && env.GOOS == 'linux' && env.GOARCH == 'amd64'
if: github.event_name == 'release'
run: |
cp ./Dockerfile ./dist
cp -rp ./resources ./dist
- name: Build and push
if: github.event_name == 'release' && env.GOOS == 'linux' && env.GOARCH == 'amd64'
if: github.event_name == 'release'
uses: docker/build-push-action@v3
with:
context: ./dist
file: ./dist/Dockerfile
platforms: linux/amd64
platforms: ${{ env.PLATFORMS }}
push: ${{ github.event_name != 'pull_request' }}
tags: |
uozi/nginx-ui:latest
uozi/nginx-ui:${{ steps.get_version.outputs.VERSION }}
- name: Prepare Demo Dockerfile
if: env.GOOS == 'linux' && env.GOARCH == 'amd64'
run: |
cp ./demo.Dockerfile ./dist
cp -rp ./resources ./dist
- name: Build and push demo
if: env.GOOS == 'linux' && env.GOARCH == 'amd64'
uses: docker/build-push-action@v3
with:
context: ./dist
file: ./dist/demo.Dockerfile
platforms: linux/amd64
platforms: ${{ env.PLATFORMS }}
push: ${{ github.event_name != 'pull_request' }}
tags: |
uozi/nginx-ui-demo:latest
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# CGO_ENABLED=1 GOOS=linux CC=x86_64-unknown-linux-gnu-gcc CXX=x86_64-unknown-linux-gnu-g++ GOARCH=amd64 go build -ldflags "-X 'github.com/0xJacky/Nginx-UI/server/settings.buildTime=$(date +%s)'" -o nginx-ui -v main.go
FROM --platform=linux/amd64 uozi/nginx-ui-base:latest
FROM --platform=$TARGETPLATFORM uozi/nginx-ui-base:latest
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
WORKDIR /app
EXPOSE 80 443

COPY resources/docker/start.sh /app/start.sh
COPY resources/docker/nginx.conf /usr/etc/nginx/nginx.conf
COPY resources/docker/nginx-ui.conf /usr/etc/nginx/conf.d/nginx-ui.conf
COPY resources/docker/nginx-ui.conf /etc/nginx/conf.d/nginx-ui.conf
COPY nginx-ui /app/nginx-ui
COPY nginx-ui-$TARGETOS-$TARGETARCH$TARGETVARIANT/nginx-ui /app/nginx-ui

RUN cd /app && chmod a+x /app/start.sh \
&& rm -f /etc/nginx/conf.d/default.conf \
Expand Down
7 changes: 5 additions & 2 deletions demo.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CGO_ENABLED=1 GOOS=linux CC=x86_64-unknown-linux-gnu-gcc CXX=x86_64-unknown-linux-gnu-g++ GOARCH=amd64 go build -ldflags "-X 'github.com/0xJacky/Nginx-UI/server/settings.buildTime=$(date +%s)'" -o nginx-ui -v main.go
FROM --platform=linux/amd64 uozi/nginx-ui-base:latest
FROM --platform=$TARGETPLATFORM uozi/nginx-ui-base:latest
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
WORKDIR /app
EXPOSE 80

Expand All @@ -9,7 +12,7 @@ COPY resources/demo/demo.db /etc/nginx-ui/database.db
COPY resources/docker/nginx.conf /etc/nginx/nginx.conf
COPY resources/docker/nginx-ui.conf /etc/nginx/conf.d/nginx-ui.conf
COPY resources/docker/start.sh /app/start.sh
COPY nginx-ui /app/nginx-ui
COPY nginx-ui-$TARGETOS-$TARGETARCH$TARGETVARIANT/nginx-ui /app/nginx-ui

RUN cd /app && chmod a+x start.sh && rm -f /etc/nginx/conf.d/default.conf

Expand Down

0 comments on commit 41ced2e

Please sign in to comment.