diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..2c043ee --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,53 @@ +name: Release + +on: + push: + branches-ignore: + - '**' + tags: + - 'v*' + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set env + run: echo "TAG_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ secrets.USERNAME }} + password: ${{ secrets.CR_PAT }} + + - name: Build and push + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: | + ghcr.io/${{ github.repository }}:latest + ghcr.io/${{ github.repository }}:${{ env.TAG_VERSION }} + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.14 + + - name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.CR_PAT }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 9a9f782..7098992 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,13 +2,10 @@ FROM golang:1.14 AS builder WORKDIR /go/src/github.com/rakutentech/passenger-go-exporter COPY go.mod go.sum ./ -RUN go mod download && go get github.com/goreleaser/goreleaser +RUN go mod download COPY . . RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /main . -ARG GITHUB_TOKEN -RUN goreleaser - FROM scratch WORKDIR /app COPY --from=builder /main /app/main