mirror of
https://github.com/elyby/chrly.git
synced 2024-12-22 21:19:55 +05:30
Обновлёна логика построения production image, используем только scratch, без alpine linux
This commit is contained in:
parent
6128c56a0c
commit
9ee3e93042
119
.gitlab-ci.yml
119
.gitlab-ci.yml
@ -1,46 +1,87 @@
|
|||||||
|
# Предполагается, что между работой "build docker container" и этапом push
|
||||||
|
# построенные docker images остаются статичными и никуда не пропадают
|
||||||
|
#
|
||||||
|
# В противном случае их нужно после каждого этапа билда пушить в registry
|
||||||
|
|
||||||
stages:
|
stages:
|
||||||
- test
|
- test
|
||||||
- build
|
- build
|
||||||
- push
|
- build_docker_image
|
||||||
|
- push
|
||||||
|
- cleanup
|
||||||
|
|
||||||
variables:
|
variables:
|
||||||
CONTAINER_IMAGE: registry.ely.by/elyby/skinsystem
|
CONTAINER_IMAGE: registry.ely.by/elyby/skinsystem
|
||||||
|
|
||||||
|
.golang_template: &setup_go_environment
|
||||||
|
image: golang:1.8.3-stretch
|
||||||
|
before_script:
|
||||||
|
- mkdir -p $GOPATH/src/$CI_PROJECT_NAMESPACE
|
||||||
|
- cp -r $(pwd) $GOPATH/src/$CI_PROJECT_PATH
|
||||||
|
- cd $GOPATH/src/$CI_PROJECT_PATH
|
||||||
|
- go get -u github.com/golang/dep/cmd/dep
|
||||||
|
- $GOPATH/bin/dep ensure
|
||||||
|
|
||||||
|
.docker_template: &setup_docker_environment
|
||||||
|
image: docker:latest
|
||||||
|
variables:
|
||||||
|
GIT_STRATEGY: none
|
||||||
|
before_script:
|
||||||
|
- docker login -u gitlab-ci -p $CI_BUILD_TOKEN registry.ely.by
|
||||||
|
- export TEMP_IMAGE_NAME="$CONTAINER_IMAGE:$CI_PIPELINE_ID"
|
||||||
|
|
||||||
test:
|
test:
|
||||||
image: golang:1.8.3-stretch
|
<<: *setup_go_environment
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
- mkdir -p $GOPATH/src/$CI_PROJECT_NAMESPACE
|
- ./script/coverage
|
||||||
- cp -r $(pwd) $GOPATH/src/$CI_PROJECT_PATH
|
|
||||||
- cd $GOPATH/src/$CI_PROJECT_PATH
|
|
||||||
- go get -u github.com/golang/dep/cmd/dep
|
|
||||||
- $GOPATH/bin/dep ensure
|
|
||||||
- ./script/coverage
|
|
||||||
|
|
||||||
build:
|
build executable:
|
||||||
image: docker:latest
|
<<: *setup_go_environment
|
||||||
stage: build
|
stage: build
|
||||||
before_script:
|
script:
|
||||||
- docker login -u gitlab-ci -p $CI_BUILD_TOKEN registry.ely.by
|
- env GOOS=linux go build -o $CI_PROJECT_DIR/minecraft-skinsystem main.go
|
||||||
script:
|
artifacts:
|
||||||
- export IMAGE_NAME="$CONTAINER_IMAGE:dev"
|
name: "${CI_JOB_STAGE} executable"
|
||||||
- docker build --pull -t $IMAGE_NAME .
|
paths:
|
||||||
- docker push $IMAGE_NAME
|
- $CI_PROJECT_DIR/minecraft-skinsystem
|
||||||
only:
|
expire_in: 1 day
|
||||||
- develop
|
|
||||||
|
|
||||||
push_tags:
|
build docker image:
|
||||||
image: docker:latest
|
<<: *setup_docker_environment
|
||||||
stage: push
|
stage: build_docker_image
|
||||||
variables:
|
script:
|
||||||
GIT_STRATEGY: none
|
- docker build -t $TEMP_IMAGE_NAME .
|
||||||
before_script:
|
only:
|
||||||
- docker login -u gitlab-ci -p $CI_BUILD_TOKEN registry.ely.by
|
- tags
|
||||||
script:
|
- develop
|
||||||
- export IMAGE_NAME="$CONTAINER_IMAGE:$CI_BUILD_TAG"
|
|
||||||
- docker tag $CONTAINER_IMAGE:dev $CONTAINER_IMAGE:latest
|
push dev:
|
||||||
- docker tag $CONTAINER_IMAGE:latest $IMAGE_NAME
|
<<: *setup_docker_environment
|
||||||
- docker push $IMAGE_NAME
|
stage: push
|
||||||
- docker push $CONTAINER_IMAGE:latest
|
script:
|
||||||
only:
|
- export IMAGE_NAME="$CONTAINER_IMAGE:dev"
|
||||||
- tags
|
- docker tag $TEMP_IMAGE_NAME $IMAGE_NAME
|
||||||
|
- docker push $IMAGE_NAME
|
||||||
|
only:
|
||||||
|
- develop
|
||||||
|
|
||||||
|
push tag:
|
||||||
|
<<: *setup_docker_environment
|
||||||
|
stage: push
|
||||||
|
script:
|
||||||
|
- export IMAGE_NAME="$CONTAINER_IMAGE:$CI_BUILD_TAG"
|
||||||
|
- export LATEST_IMAGE_NAME="$CONTAINER_IMAGE:latest"
|
||||||
|
- docker tag $TEMP_IMAGE_NAME $IMAGE_NAME
|
||||||
|
- docker tag $TEMP_IMAGE_NAME $LATEST_IMAGE_NAME
|
||||||
|
- docker push $IMAGE_NAME
|
||||||
|
- docker push $LATEST_IMAGE_NAME
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
|
||||||
|
cleanup temp image:
|
||||||
|
<<: *setup_docker_environment
|
||||||
|
stage: cleanup
|
||||||
|
when: always
|
||||||
|
script:
|
||||||
|
- docker rmi $TEMP_IMAGE_NAME
|
||||||
|
32
Dockerfile
32
Dockerfile
@ -1,32 +1,6 @@
|
|||||||
FROM golang:1.9-alpine
|
FROM scratch
|
||||||
|
|
||||||
RUN mkdir -p /go/src/elyby/minecraft-skinsystem \
|
COPY ./minecraft-skinsystem /app/
|
||||||
/go/src/elyby/minecraft-skinsystem/data/capes \
|
|
||||||
&& ln -s /go/src/elyby/minecraft-skinsystem /go/src/app
|
|
||||||
|
|
||||||
WORKDIR /go/src/app
|
ENTRYPOINT ["/app/minecraft-skinsystem"]
|
||||||
|
|
||||||
COPY ./Gopkg.* /go/src/app/
|
|
||||||
COPY ./main.go /go/src/app/
|
|
||||||
COPY ./bootstrap /go/src/app/bootstrap
|
|
||||||
COPY ./cmd /go/src/app/cmd
|
|
||||||
COPY ./daemon /go/src/app/daemon
|
|
||||||
COPY ./db /go/src/app/db
|
|
||||||
COPY ./model /go/src/app/model
|
|
||||||
COPY ./repositories /go/src/app/repositories
|
|
||||||
COPY ./ui /go/src/app/ui
|
|
||||||
COPY ./utils /go/src/app/utils
|
|
||||||
|
|
||||||
RUN apk add --no-cache git \
|
|
||||||
&& go get -u github.com/golang/dep/cmd/dep \
|
|
||||||
&& dep ensure \
|
|
||||||
&& go clean -i github.com/golang/dep \
|
|
||||||
&& rm -rf $GOPATH/src/github.com/golang/dep \
|
|
||||||
&& apk del git \
|
|
||||||
&& go build main.go \
|
|
||||||
&& mv main /usr/local/bin/minecraft-skinsystem
|
|
||||||
|
|
||||||
EXPOSE 80
|
|
||||||
|
|
||||||
ENTRYPOINT ["minecraft-skinsystem"]
|
|
||||||
CMD ["serve"]
|
CMD ["serve"]
|
||||||
|
23
Dockerfile-dev
Normal file
23
Dockerfile-dev
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
FROM golang:1.9-alpine
|
||||||
|
|
||||||
|
RUN mkdir -p /go/src/elyby/minecraft-skinsystem \
|
||||||
|
/go/src/elyby/minecraft-skinsystem/data/capes \
|
||||||
|
&& ln -s /go/src/elyby/minecraft-skinsystem /go/src/app
|
||||||
|
|
||||||
|
WORKDIR /go/src/app
|
||||||
|
|
||||||
|
COPY ./ /go/src/app/
|
||||||
|
|
||||||
|
RUN apk add --no-cache git \
|
||||||
|
&& go get -u github.com/golang/dep/cmd/dep \
|
||||||
|
&& dep ensure \
|
||||||
|
&& go clean -i github.com/golang/dep \
|
||||||
|
&& rm -rf $GOPATH/src/github.com/golang/dep \
|
||||||
|
&& apk del git \
|
||||||
|
&& go build main.go \
|
||||||
|
&& mv main /usr/local/bin/minecraft-skinsystem
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
ENTRYPOINT ["minecraft-skinsystem"]
|
||||||
|
CMD ["serve"]
|
Loading…
Reference in New Issue
Block a user