Skip to content

Commit e57c3ed

Browse files
authored
Ubiquitous docker-publish.yml
1 parent 59d8378 commit e57c3ed

1 file changed

Lines changed: 30 additions & 25 deletions

File tree

.github/workflows/docker-publish.yml

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,58 @@ name: Build
22

33
on:
44
push:
5-
workflow_dispatch:
5+
branches: [ master, testing ]
6+
workflow_dispatch:
67
inputs:
7-
dnscrypt-proxy-release:
8-
description: 'DNSCrypt Proxy Release'
9-
required: true
8+
dnscrypt_proxy_release:
9+
description: "DNSCrypt Proxy Release (blank = latest upstream)"
10+
required: false
1011

1112
env:
1213
REGISTRY: docker.io
1314
IMAGE_NAME: xtr0py/dnscrypt-proxy-2-docker
1415

15-
1616
jobs:
1717
build:
1818
runs-on: ubuntu-latest
1919
permissions:
2020
contents: read
21-
env:
22-
DNSCRYPT_PROXY_VERSION: ${{ github.event.inputs.version }}
23-
24-
steps:
25-
- name: Checkout repository
26-
uses: actions/checkout@v2
2721

28-
- name: Setup default version
29-
run: echo "DNSCRYPT_PROXY_VERSION=2.1.15" >> $GITHUB_ENV
30-
if: ${{ env.DNSCRYPT_PROXY_VERSION == '' }}
22+
steps:
23+
- uses: actions/checkout@v4
3124

32-
- name: Setup Docker buildx
33-
uses: docker/setup-buildx-action@v1
25+
- name: Determine DNSCrypt version
26+
shell: bash
27+
run: |
28+
VERSION="${{ github.event.inputs.dnscrypt_proxy_release }}"
29+
if [ -z "$VERSION" ]; then
30+
VERSION="$(curl -fsSL https://api.github.com/repos/DNSCrypt/dnscrypt-proxy/releases/latest \
31+
| python -c "import sys,json; print(json.load(sys.stdin)['tag_name'].lstrip('v'))")"
32+
fi
33+
echo "DNSCRYPT_PROXY_VERSION=$VERSION" >> "$GITHUB_ENV"
3434
35+
- uses: docker/setup-buildx-action@v3
3536

36-
# Login against a Docker registry except on PR
37-
- name: Log into registry ${{ env.REGISTRY }}
38-
uses: docker/login-action@v1
37+
- uses: docker/login-action@v3
3938
with:
4039
registry: ${{ env.REGISTRY }}
4140
username: ${{ secrets.DOCKERHUB_USERNAME }}
4241
password: ${{ secrets.DOCKERHUB_TOKEN }}
4342

43+
- name: Docker metadata (tags)
44+
id: meta
45+
uses: docker/metadata-action@v5
46+
with:
47+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
48+
tags: |
49+
type=raw,value=${{ env.DNSCRYPT_PROXY_VERSION }}
50+
type=raw,value=latest,enable=${{ github.ref_name == 'master' }}
51+
type=raw,value=testing,enable=${{ github.ref_name == 'testing' }}
4452
45-
# Build and push Docker image with Buildx (don't push on PR)
46-
# https://github.com/docker/build-push-action
47-
- name: Build and push Docker image
48-
uses: docker/build-push-action@v2
53+
- uses: docker/build-push-action@v6
4954
with:
5055
context: .
5156
platforms: linux/amd64
52-
build-args: VERSION=${{ env.DNSCRYPT_PROXY_VERSION }}
53-
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.DNSCRYPT_PROXY_VERSION }}
57+
build-args: VERSION=${{ env.DNSCRYPT_PROXY_VERSION }}
58+
tags: ${{ steps.meta.outputs.tags }}
5459
push: true

0 commit comments

Comments
 (0)