diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..1301477 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,50 @@ +name: Publish Docker image + +on: + push: + tags: + - '*' + workflow_dispatch: + inputs: + name: + description: 'reason' + required: false +jobs: + push_to_registries: + name: Push Docker image to multiple registries + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + steps: + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: | + justsong/message-pusher + ghcr.io/${{ github.repository }} + + - name: Build and push Docker images + uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 3994e0c..6485728 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,20 +6,21 @@ RUN npm install RUN npm run build FROM golang AS builder2 + ENV GO111MODULE=on \ CGO_ENABLED=1 \ GOOS=linux \ GOARCH=amd64 - WORKDIR /build COPY . . COPY --from=builder /build/build ./web/build RUN go mod download -RUN go build -ldflags "-s -w" -o message-pusher +RUN go build -ldflags "-s -w -extldflags '-static'" -o message-pusher FROM scratch ENV PORT=3000 COPY --from=builder2 /build/message-pusher / EXPOSE 3000 +WORKDIR /data ENTRYPOINT ["/message-pusher"] diff --git a/common/constants.go b/common/constants.go index a195081..666054d 100644 --- a/common/constants.go +++ b/common/constants.go @@ -15,7 +15,7 @@ var Footer = "" // Any options with "Secret", "Token" in its key won't be return by GetOptions var SessionSecret = uuid.New().String() -var SQLitePath = ".message-pusher.db" +var SQLitePath = "message-pusher.db" var OptionMap map[string]string var OptionMapRWMutex sync.RWMutex