-
Notifications
You must be signed in to change notification settings - Fork 45
41 lines (40 loc) · 1.22 KB
/
dockerhub.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
name: Build and push Docker image
on:
push: {}
workflow_dispatch: {}
schedule:
- cron: '30 5 * * *'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set Docker image tag version
id: image-name
run: |
case "$GITHUB_REF" in
refs/heads/master)
TAG=latest;;
*)
echo "Branch not recognized" >&2
exit 1;;
esac
echo "tag=$TAG" > "$GITHUB_OUTPUT"
echo "name=ustclug/neatdns:$TAG" >> "$GITHUB_OUTPUT"
- name: Build Docker image
run: |
IMAGE="${{ steps.image-name.outputs.name }}"
if ! docker pull "$IMAGE";
then
echo "No cached image found, building from scratch"
docker build -t build-image .
else
docker build --cache-from "$IMAGE" -t build-image .
fi
- name: Push to Docker Hub
if: "github.repository == 'ustclug/neatdns'"
run: |
IMAGE="${{ steps.image-name.outputs.name }}"
docker tag build-image "$IMAGE"
docker login -u "${{ secrets.DOCKER_USER }}" -p "${{ secrets.DOCKER_PASS }}"
docker push "$IMAGE"