diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..7e9cff1 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,104 @@ +name: Docker +on: + push: + branches: + - '**' + tags: + - 'v*' + paths: + - 'go.sum' + - 'go.mod' + - '**.go' + - .github/workflows/docker.yml + - dist.Dockerfile + pull_request: + branches: + - main + paths: + - '**.go' + - 'go.sum' + - 'go.mod' + - dist.Dockerfile + - .github/workflows/docker.yml + +permissions: + actions: write + packages: write + id-token: write + attestations: write + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + Docker: + runs-on: ubuntu-latest + env: + GO111MODULE: on + steps: + - name: Login to DockerHub + uses: docker/login-action@v3 + if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }} + with: + username: cyb3rjak3 + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Login to GitHub Container Registry + if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }} + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Docker Meta + id: meta + uses: docker/metadata-action@v5 + with: + images: cyb3rjak3/cloudflare-utils,ghcr.io/cyb3r-jak3/cloudflare-utils + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + path: cloudflare-utils + + - name: Build + uses: docker/build-push-action@v6 + id: build + with: + context: cloudflare-utils + push: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }} + platforms: linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6, linux/386 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + file: cloudflare-utils/dist.Dockerfile + cache-from: type=gha + cache-to: type=gha,mode=max + sbom: true + provenance: mode=max + + - name: Docker Hub Description + uses: peter-evans/dockerhub-description@v4 + if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }} + with: + username: cyb3rjak3 + password: ${{ secrets.DOCKER_PASSWORD }} + repository: cyb3rjak3/cloudflare-utils + readme-filepath: cloudflare-utils/README.md + + - name: GitHub Container Attestation + uses: actions/attest-build-provenance@v1 + id: attest + if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }} + with: + subject-name: ghcr.io/cyb3r-jak3/cloudflare-utils + subject-digest: ${{ steps.build.outputs.digest }} + push-to-registry: true \ No newline at end of file diff --git a/.github/workflows/golang.yml b/.github/workflows/golang.yml index 28acc24..34d0d08 100644 --- a/.github/workflows/golang.yml +++ b/.github/workflows/golang.yml @@ -29,7 +29,6 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true - jobs: Snapshot: if: ${{ startsWith(github.ref, 'refs/tags/v') == false }} @@ -81,61 +80,6 @@ jobs: name: cloudflare-utils path: cmd/cloudflare-utils/dist/* - Docker: - runs-on: ubuntu-latest - env: - GO111MODULE: on - steps: - - name: Login to DockerHub - uses: docker/login-action@v3 - if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }} - with: - username: cyb3rjak3 - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Login to GitHub Container Registry - if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }} - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Docker Meta - id: meta - uses: docker/metadata-action@v5 - with: - images: cyb3rjak3/cloudflare-utils,ghcr.io/cyb3r-jak3/cloudflare-utils - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Checkout code - uses: actions/checkout@v4 - - - name: Build - uses: docker/build-push-action@v6 - with: - push: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }} - platforms: linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6, linux/386 - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - file: dist.Dockerfile - cache-from: type=gha - cache-to: type=gha,mode=max - sbom: true - - - name: Docker Hub Description - uses: peter-evans/dockerhub-description@v4 - if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }} - with: - username: cyb3rjak3 - password: ${{ secrets.DOCKER_PASSWORD }} - repository: cyb3rjak3/cloudflare-utils - Release: if: startsWith(github.ref, 'refs/tags/v') runs-on: windows-latest diff --git a/dist.Dockerfile b/dist.Dockerfile index c95d451..71d6414 100644 --- a/dist.Dockerfile +++ b/dist.Dockerfile @@ -4,7 +4,9 @@ WORKDIR /usr/app ENV CGO_ENABLED=0 RUN apk update && apk -U --no-cache add git make build-base ca-certificates && git config --global --add safe.directory '*' COPY . . -RUN make build +RUN go mod download +ENV GOCACHE=/root/.cache/go-build +RUN --mount=type=cache,target="/root/.cache/go-build" make build FROM scratch COPY --from=builder /usr/app/cloudflare-utils /