From 7722577a83febfc486c2dcc5c268910c86b32efe Mon Sep 17 00:00:00 2001 From: Lasse Bjerre Date: Thu, 10 Jun 2021 20:54:43 +0200 Subject: [PATCH] Add GoReleaser --- .github/workflows/build.yml | 43 +++++++++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 24 --------------------- .goreleaser.yml | 17 +++++++++++++++ Dockerfile | 13 ++--------- 4 files changed, 62 insertions(+), 35 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/ci.yml create mode 100644 .goreleaser.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..1b6cb49 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,43 @@ +name: build + +on: + push: + tags: + - 'v*' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - + name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.16 + - + name: Cache Go modules + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - + name: Docker Login + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v2 + with: + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 84a3d53..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: ci -on: - push: - branches: - - 'main' -jobs: - docker: - runs-on: ubuntu-latest - steps: - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push - id: docker_build - uses: docker/build-push-action@v2 - with: - push: true - tags: ordspilleren/changemonitor:latest - - name: Image digest - run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..06aa0a7 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,17 @@ +project_name: changemonitor +builds: + - env: [CGO_ENABLED=0] + goos: + - linux + - windows + - darwin + goarch: + - amd64 + - arm64 +dockers: + - goos: linux + goarch: amd64 + image_templates: + - "ordspilleren/{{.ProjectName}}:latest" + - "ordspilleren/{{.ProjectName}}:{{ .Tag }}" + dockerfile: Dockerfile diff --git a/Dockerfile b/Dockerfile index 70db2ad..4c1b129 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,8 @@ -# Build image -FROM golang:alpine AS build -WORKDIR /app -COPY go.mod go.sum ./ -RUN go mod download -COPY . ./ -RUN CGO_ENABLED=0 GOOS=linux go build -o ./out/app . - -# Runtime image FROM alpine -COPY --from=build /app/out/app /usr/local/bin/changemonitor +COPY changemonitor /usr/bin/changemonitor RUN apk add --no-cache tzdata ENV CONFIG_FILE=/config/config.json ENV STORAGE_DIRECTORY=/data ENV CHROME_WS=ws://127.0.0.1:9222 ENV ENABLE_WEBUI=false -ENTRYPOINT ["/usr/local/bin/changemonitor"] \ No newline at end of file +ENTRYPOINT ["/usr/bin/changemonitor"] \ No newline at end of file