diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 0000000..68203da --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,41 @@ +name: Build Docker Image + +on: + push: + tags: + - 'v*' + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Check out + uses: actions/checkout@v2 + + - name: Get tag + uses: olegtarasov/get-tag@v2 + id: tagName + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - 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: + context: . + push: true + platforms: linux/amd64,linux/arm64 + tags: tobyxdd/hysteria:latest,tobyxdd/hysteria:${{ env.GIT_TAG_NAME }} + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/Dockerfile b/Dockerfile index c023ea0..7e794f5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,40 +1,30 @@ -FROM golang:1.14.7-alpine3.12 AS builder +FROM golang:alpine AS builder LABEL maintainer="mritd " -# The following parameters are used to set compilation information(such as compilation time, -# commit id, etc.). Use "docker build --build-arg VERSION=1.1.1 ..." to set these parameters. -# These parameters can be set automatically through CI Server. -ARG VERSION="Unknown" -ARG COMMIT="Unknown" -ARG TIMESTAMP="Unknown" - # GOPROXY is disabled by default, use: # docker build --build-arg GOPROXY="https://goproxy.io" ... # to enable GOPROXY. ARG GOPROXY="" -ENV VERSION ${VERSION} -ENV COMMIT ${COMMIT} -ENV TIMESTAMP ${TIMESTAMP} ENV GOPROXY ${GOPROXY} -# go mod is always enabled -ENV GO111MODULE on - COPY . /go/src/github.com/tobyxdd/hysteria WORKDIR /go/src/github.com/tobyxdd/hysteria/cmd -# TODO: Is it necessary to remove "-w -s" to add debugging information? RUN set -ex \ + && apk add git \ + && export VERSION=$(git describe --tags) \ + && export COMMIT=$(git rev-parse HEAD) \ + && export TIMESTAMP=$(date "+%F %T") \ && go build -o /go/bin/hysteria -ldflags \ "-w -s -X 'main.appVersion=${VERSION}' \ -X 'main.appCommit=${COMMIT}' \ -X 'main.appDate=${TIMESTAMP}'" # multi-stage builds to create the final image -FROM alpine:3.12 AS dist +FROM alpine AS dist LABEL maintainer="mritd " @@ -50,4 +40,4 @@ RUN set -ex \ COPY --from=builder /go/bin/hysteria /usr/local/bin/hysteria -ENTRYPOINT ["hysteria"] \ No newline at end of file +ENTRYPOINT ["hysteria"]