build: Add Docker CI/CD
This commit is contained in:
74
.github/workflows/docker.yaml
vendored
Normal file
74
.github/workflows/docker.yaml
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
name: Docker CI
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
schedule:
|
||||
- cron: "0 0 * * 0"
|
||||
|
||||
jobs:
|
||||
build-linux:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
strategy:
|
||||
matrix:
|
||||
target:
|
||||
- src: .
|
||||
image: ghcr.io/pojntfx/weron
|
||||
arch: "linux/amd64,linux/arm/v5,linux/arm/v7,linux/arm64/v8,linux/386,linux/mips64le,linux/ppc64le,linux/s390x"
|
||||
|
||||
steps:
|
||||
- name: Maximize build space
|
||||
run: |
|
||||
sudo rm -rf /usr/share/dotnet
|
||||
sudo rm -rf /usr/local/lib/android
|
||||
sudo rm -rf /opt/ghc
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Set up metadata
|
||||
id: meta
|
||||
uses: docker/metadata-action@v3
|
||||
with:
|
||||
images: ${{ matrix.target.image }}
|
||||
tags: type=semver,pattern={{version}}
|
||||
- name: Build image
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: ${{ matrix.target.src }}
|
||||
file: ${{ matrix.target.src }}/Dockerfile
|
||||
platforms: ${{ matrix.target.arch }}
|
||||
push: false
|
||||
tags: ${{ matrix.target.image }}:unstable
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
- name: Push pre-release image to Docker Hub
|
||||
if: ${{ github.ref == 'refs/heads/main' }}
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: ${{ matrix.target.src }}
|
||||
file: ${{ matrix.target.src }}/Dockerfile
|
||||
platforms: ${{ matrix.target.arch }}
|
||||
push: true
|
||||
tags: ${{ matrix.target.image }}:unstable
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
- name: Push release image to Docker Hub
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: ${{ matrix.target.src }}
|
||||
file: ${{ matrix.target.src }}/Dockerfile
|
||||
platforms: ${{ matrix.target.arch }}
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
26
Dockerfile
Normal file
26
Dockerfile
Normal file
@@ -0,0 +1,26 @@
|
||||
# Build container
|
||||
FROM golang:bullseye AS build
|
||||
|
||||
# Setup environment
|
||||
RUN mkdir -p /data
|
||||
WORKDIR /data
|
||||
|
||||
# Build the release
|
||||
COPY . .
|
||||
RUN make
|
||||
|
||||
# Extract the release
|
||||
RUN mkdir -p /out
|
||||
RUN cp out/weron /out/weron
|
||||
|
||||
# Release container
|
||||
FROM debian:bullseye
|
||||
|
||||
# Add certificates
|
||||
RUN apt update
|
||||
RUN apt install -y ca-certificates
|
||||
|
||||
# Add the release
|
||||
COPY --from=build /out/weron /usr/local/bin/weron
|
||||
|
||||
CMD /usr/local/bin/weron
|
Reference in New Issue
Block a user