diff --git a/.github/workflows/dockerpush.yml b/.github/workflows/dockerpush.yml new file mode 100644 index 00000000..3f2d2406 --- /dev/null +++ b/.github/workflows/dockerpush.yml @@ -0,0 +1,44 @@ +name: Publish Docker image +on: + push: + tags: + - "v*.*.*" +jobs: + main: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v2 + + - name: Save tag in env variable + run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + + - name: Save repo in env variable + run: echo "REPO_NAME=${{ github.event.repository.name }}" >> $GITHUB_ENV + + - name: Print release and repo name for debugging + run: | + echo $RELEASE_VERSION + echo $REPO_NAME + + - 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.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + push: true + tags: | + restic/${{ env.REPO_NAME }}:latest + restic/${{ env.REPO_NAME }}:${{ env.RELEASE_VERSION }} + platforms: linux/amd64,linux/arm/v7 diff --git a/Dockerfile b/Dockerfile index 50fe70f3..3742776e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,23 @@ -FROM alpine +FROM golang:alpine3.13 AS builder +LABEL stage=builder +WORKDIR /workspace +COPY . . +RUN CGO_ENABLED=0 go build -o rest-server ./cmd/rest-server + + +FROM alpine:3.13 AS final +WORKDIR /app ENV DATA_DIRECTORY /data ENV PASSWORD_FILE /data/.htpasswd +ENV PATH="/app:${PATH}" RUN apk add --no-cache --update apache2-utils -COPY docker/create_user /usr/bin/ -COPY docker/delete_user /usr/bin/ -COPY docker/entrypoint.sh /entrypoint.sh -COPY rest-server /usr/bin +COPY docker/. . +COPY --from=builder /workspace/rest-server . VOLUME /data EXPOSE 8000 -CMD [ "/entrypoint.sh" ] +CMD [ "./entrypoint.sh" ]