diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b836ab73..84b8302c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,42 +1,51 @@ name: CI Pipeline on: - pull_request: - branches: - - main - push: - branches: - - main - workflow_dispatch: + pull_request: + branches: + - main + push: + branches: + - main + workflow_dispatch: jobs: - ci: - name: Continuous Integration - runs-on: ubuntu-latest - - steps: - - name: Checkout Code - uses: actions/checkout@v4 - - - name: Setup Go - uses: actions/setup-go@v5 - with: - go-version-file: "go.mod" - cache-dependency-path: "go.sum" - - - - name: golangci-lint - uses: golangci/golangci-lint-action@v6 - with: - version: latest - - - name: Build binary - run: | - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o immich-linux-amd64 -ldflags="-s -w -extldflags=-static" main.go - CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o immich-linux-arm64 -ldflags="-s -w -extldflags=-static" main.go - CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o immich-windows-amd64.exe -ldflags="-s -w -extldflags=-static" main.go - CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o immich-darwin-amd64 -ldflags="-s -w -extldflags=-static" main.go - - - name: Run tests - run: | - go test --race -v -count=1 -coverprofile=coverage.out ./... + ci: + name: Continuous Integration + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + cache-dependency-path: "go.sum" + + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: latest + + - name: Build binary + run: | + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o immich-linux-amd64 -ldflags="-s -w -extldflags=-static" main.go + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o immich-linux-arm64 -ldflags="-s -w -extldflags=-static" main.go + CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o immich-windows-amd64.exe -ldflags="-s -w -extldflags=-static" main.go + CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o immich-darwin-amd64 -ldflags="-s -w -extldflags=-static" main.go + + - name: Upload binaries as artifact + uses: actions/upload-artifact@v3 + with: + name: binaries + path: | + immich-linux-amd64 + immich-linux-arm64 + immich-windows-amd64.exe + immich-darwin-amd64 + + - name: Run tests + run: | + go test --race -v -count=1 -coverprofile=coverage.out ./... diff --git a/.github/workflows/ci_docker.yml b/.github/workflows/ci_docker.yml new file mode 100644 index 00000000..1911eeb8 --- /dev/null +++ b/.github/workflows/ci_docker.yml @@ -0,0 +1,26 @@ +name: docker image ci + +on: + pull_request: + branches: + - main + push: + branches: + - main + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Build Docker Image + uses: docker/build-push-action@v6 + with: + push: false + tags: ${{github.repository_owner}}/immich-go \ No newline at end of file diff --git a/.github/workflows/publish_docker.yml b/.github/workflows/publish_docker.yml new file mode 100644 index 00000000..cc6539ad --- /dev/null +++ b/.github/workflows/publish_docker.yml @@ -0,0 +1,87 @@ +name: publish docker image + +on: + workflow_dispatch: + push: + # Publish when tagging + tags: [ '*' ] + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + GH_IMAGE_NAME: ${{github.repository_owner}}/immich-go + DH_IMAGE_NAME: ${{github.repository_owner}}/immich-go + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + 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@v4 + + # Install the cosign tool + # https://github.com/sigstore/cosign-installer + - name: Install cosign + uses: sigstore/cosign-installer@main #v2.6.0 + - + # Add support for more platforms with QEMU (optional) + # https://github.com/docker/setup-qemu-action + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Setup Docker buildx + uses: docker/setup-buildx-action@v3 + - + name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + # Login against a Docker registry + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@v3 + 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@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.GH_IMAGE_NAME }},${{ env.DH_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@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 + with: + platforms: linux/amd64,linux/arm64 + push: true + 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 + 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 -y {}@${{ steps.build-and-push.outputs.digest }} + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..dc2d9230 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM golang:1.23 AS builder + +WORKDIR /go/src/app +COPY . . +RUN go mod download && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /go/bin/immich-go -ldflags="-s -w -extldflags=-static" main.go + +FROM gcr.io/distroless/base-debian12 + +COPY --from=builder /go/bin/immich-go / +CMD ["/immich-go"] \ No newline at end of file