From 2f82b81bfa95b993f204c3f252ab872b9ea42d1a Mon Sep 17 00:00:00 2001 From: taoky Date: Sun, 24 Sep 2023 03:48:13 +0800 Subject: [PATCH] Add CI --- .github/workflows/dockerhub.yml | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/dockerhub.yml diff --git a/.github/workflows/dockerhub.yml b/.github/workflows/dockerhub.yml new file mode 100644 index 0000000..4ffae20 --- /dev/null +++ b/.github/workflows/dockerhub.yml @@ -0,0 +1,42 @@ +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/bind9) + TAG=bind9;; + *) + echo "Branch not recognized" >&2 + exit;; + esac + + : ${TAG:=latest} + echo "::set-output name=tag::$TAG" + echo "::set-output name=name::ustclug/neatdns:$TAG" + - 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" \ No newline at end of file