add docker build and push workflow

This commit is contained in:
mxmlndml
2023-08-28 14:32:13 +02:00
parent a5880ee555
commit 45b7040196
6 changed files with 131 additions and 33 deletions

5
.dockerignore Normal file
View File

@@ -0,0 +1,5 @@
node_modules
.git
.gitignore
*.md
dist

View File

@@ -0,0 +1,99 @@
name: Docker Build and Push
on:
push:
tags:
- "*"
env:
REGISTRY_IMAGE: mxmlndml/cloudflare-dynamic-dns
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm/v7
- linux/arm64
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY_IMAGE }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push by digest
id: build
uses: docker/build-push-action@v4
with:
context: .
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
- name: Export digest
run: |
mkdir -p /tmp/digests
digest=${{ steps.build.outputs.digest }}
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v3
with:
name: digests
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge:
runs-on: ubuntu-latest
needs:
- build
steps:
- name: Download digests
uses: actions/download-artifact@v3
with:
name: digests
path: /tmp/digests
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY_IMAGE }}
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}

View File

@@ -1,28 +1,18 @@
FROM node:alpine AS base FROM node:slim AS base
# add pnpm ENV PNPM_HOME="/pnpm"
ENV PATH="${PNPM_HOME}:${PATH}"
RUN corepack enable RUN corepack enable
RUN corepack prepare pnpm@latest --activate COPY . /app
FROM base as deps
WORKDIR /app WORKDIR /app
# install dependencies with pnpm
COPY package.json pnpm-lock.yaml* ./
RUN pnpm i --frozen-lockfile
FROM base as prod-deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
FROM base as builder FROM base AS build
WORKDIR /app RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
COPY --from=deps /app/node_modules ./node_modules RUN pnpm run build
COPY . .
RUN pnpm build
FROM base
FROM base as runner COPY --from=prod-deps /app/node_modules /app/node_modules
WORKDIR /app COPY --from=build /app/dist /app/dist
COPY --from=builder /app/dist ./dist CMD [ "pnpm", "start" ]
COPY --from=builder /app/node_modules ./node_modules
USER node
CMD ["node", "./dist/index.js"]

View File

@@ -1,2 +1,6 @@
# cloudflare-ddns # Cloudflare Dynamic DNS
This Docker container provides a simple and efficient solution for dynamic DNS updates using Cloudflare DNS. It allows you to automatically update your DNS records in Cloudflare at specified intervals, ensuring that your services are always accessible through a domain name.
This Docker container provides a simple and efficient solution for dynamic DNS
updates using Cloudflare DNS. It allows you to automatically update your DNS
records in Cloudflare at specified intervals, ensuring that your services are
always accessible through a domain name.

View File

@@ -1,6 +1,6 @@
services: services:
cloudflare-ddns: cloudflare-dynamic-dns:
image: cloudflare-ddns image: mxmlndml/cloudflare-dynamic-dns:latest
restart: always restart: always
environment: environment:
- API_KEY=123 - API_KEY=123

View File

@@ -1,5 +1,5 @@
{ {
"name": "cloudflare-ddns", "name": "cloudflare-dynamic-dns",
"version": "1.0.0", "version": "1.0.0",
"description": "", "description": "",
"main": "dist/index.js", "main": "dist/index.js",