Merge pull request #3520 from nxt-engineering/Docker

Docker Multistage build
This commit is contained in:
MichaelEischer 2021-10-24 17:37:54 +02:00 committed by GitHub
commit 829c0a67af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 73 additions and 7 deletions

12
.dockerignore Normal file
View File

@ -0,0 +1,12 @@
# Folders
.git/
.github/
changelog/
doc/
docker/
helpers/
# Files
.gitignore
.golangci.yml
*.md

View File

@ -269,3 +269,44 @@ jobs:
echo "check if go.mod and go.sum are up to date"
go mod tidy
git diff --exit-code go.mod go.sum
docker:
name: docker
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
# list of Docker images to use as base name for tags
images: |
restic/restic
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
push: false
context: .
file: docker/Dockerfile
pull: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

View File

@ -1,7 +1,18 @@
FROM alpine:latest
FROM golang:1.16-alpine AS builder
COPY restic /usr/bin
WORKDIR /go/src/github.com/restic/restic
# Caching dependencies
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN go run build.go
FROM alpine:latest AS restic
RUN apk add --update --no-cache ca-certificates fuse openssh-client tzdata
COPY --from=builder /go/src/github.com/restic/restic/restic /usr/bin
ENTRYPOINT ["/usr/bin/restic"]

View File

@ -2,10 +2,12 @@
set -e
echo "Build binary using golang docker image"
docker run --rm -ti \
-v "`pwd`":/go/src/github.com/restic/restic \
-w /go/src/github.com/restic/restic golang:1.16-alpine go run build.go
export DOCKER_BUILDKIT=${DOCKER_BUILDKIT-1}
echo "Build docker image restic/restic:latest"
docker build --rm -t restic/restic:latest -f docker/Dockerfile .
docker build \
--rm \
--pull \
--file docker/Dockerfile \
--tag restic/restic:latest \
.