From a5e3407aa1a47051083740b22756b7d8a4db39fa Mon Sep 17 00:00:00 2001 From: M3chD09 Date: Sat, 4 Mar 2023 09:27:10 +0000 Subject: [PATCH 1/6] add Dockerfile and docker-compose.yml --- Dockerfile | 9 +++++++++ docker-compose.yml | 6 ++++++ 2 files changed, 15 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..da1f080 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM golang AS builder +COPY . /NeverIdle +WORKDIR /NeverIdle +RUN CGO_ENABLED=0 go build -ldflags "-s -w" -o NeverIdle \ + && chmod +x NeverIdle + +FROM scratch +COPY --from=builder /NeverIdle/NeverIdle /app/NeverIdle +CMD ["/app/NeverIdle"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e14fe93 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,6 @@ +version: '3.9' +services: + app: + build: ./ + command: /app/NeverIdle -c 2h -m 2 -n 4h + restart: always From 67ca79eaf7d3a3e55022a0eac2641b3de416fc52 Mon Sep 17 00:00:00 2001 From: M3chD09 Date: Sat, 4 Mar 2023 09:28:48 +0000 Subject: [PATCH 2/6] add docker-publish.yml --- .github/workflows/docker-publish.yml | 96 ++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 .github/workflows/docker-publish.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..463c14f --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,96 @@ +name: Docker + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +on: + schedule: + - cron: '24 10 * * *' + push: + branches: [ "master" ] + # Publish semver tags as releases. + tags: [ 'v*.*.*' ] + pull_request: + branches: [ "master" ] + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Install the cosign tool except on PR + # https://github.com/sigstore/cosign-installer + - name: Install cosign + if: github.event_name != 'pull_request' + uses: sigstore/cosign-installer@f3c664df7af409cb4873aa5068053ba9d61a57b6 #v2.6.0 + with: + cosign-release: 'v1.13.1' + + + # Workaround: https://github.com/docker/build-push-action/issues/461 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + + # Sign the resulting Docker image digest except on PRs. + # This will only write to the public Rekor transparency log when the Docker + # repository is public to avoid leaking data. If you would like to publish + # transparency data even for private images, pass --force to cosign below. + # https://github.com/sigstore/cosign + - name: Sign the published Docker image + if: ${{ github.event_name != 'pull_request' }} + env: + COSIGN_EXPERIMENTAL: "true" + # This step uses the identity token to provision an ephemeral certificate + # against the sigstore community Fulcio instance. + run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.build-and-push.outputs.digest }} From 56f59f3b6635013315228617a4cee7fd4b0d6ce8 Mon Sep 17 00:00:00 2001 From: M3chD09 Date: Sat, 4 Mar 2023 10:12:25 +0000 Subject: [PATCH 3/6] linux/arm64 platforms support --- .github/workflows/docker-publish.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 463c14f..009f7bf 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -75,6 +75,7 @@ jobs: uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a with: context: . + platforms: linux/amd64,linux/arm64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} From 036eadcd8cf976f9df878601e94f0251998f05da Mon Sep 17 00:00:00 2001 From: M3chD09 Date: Sat, 4 Mar 2023 10:19:48 +0000 Subject: [PATCH 4/6] remove schedule --- .github/workflows/docker-publish.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 009f7bf..eac9df8 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -6,8 +6,6 @@ name: Docker # documentation. on: - schedule: - - cron: '24 10 * * *' push: branches: [ "master" ] # Publish semver tags as releases. From 21debb0d75afba7f0024b3e8f1e30970cbfbd741 Mon Sep 17 00:00:00 2001 From: M3chD09 Date: Sat, 4 Mar 2023 10:25:15 +0000 Subject: [PATCH 5/6] add docker usage in readme --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index f8c7e94..56a4728 100644 --- a/README.md +++ b/README.md @@ -40,3 +40,20 @@ MJJ 们估计会喜欢这个。感谢脚本作者 @Ansen 格式同 CPU。会定期执行一次 Ookla Speed Test(还会输出结果哦!) *启动该程序后即立刻执行一次你配置的所有功能,可以观察效果。* + +## Docker + +```shell +docker run ghcr.io/m3chd09/neveridle /app/NeverIdle -c 2h -m 2 -n 4h +``` + +docker-compose.yml + +```yaml +version: '3.9' +services: + app: + image: ghcr.io/m3chd09/neveridle + command: /app/NeverIdle -c 2h -m 2 -n 4h + restart: always +``` From 5ee580af37d33d58ddef784207e4e03240451c05 Mon Sep 17 00:00:00 2001 From: M3chD09 Date: Sun, 5 Mar 2023 12:13:42 +0000 Subject: [PATCH 6/6] mount certificates in container --- README.md | 2 ++ docker-compose.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index bf31248..4ea8e1b 100644 --- a/README.md +++ b/README.md @@ -59,4 +59,6 @@ services: image: ghcr.io/m3chd09/neveridle command: /app/NeverIdle -c 2h -m 2 -n 4h restart: always + volumes: + - /etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt:ro ``` diff --git a/docker-compose.yml b/docker-compose.yml index e14fe93..2db7c82 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,3 +4,5 @@ services: build: ./ command: /app/NeverIdle -c 2h -m 2 -n 4h restart: always + volumes: + - /etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt:ro