Compare commits
3 Commits
main
...
lesson3-ci
Author | SHA1 | Date | |
---|---|---|---|
dfd16e74c5 | |||
429f1f3a6e | |||
2d0c627dc9 |
44
ci/.gitlab-ci.yml
Normal file
44
ci/.gitlab-ci.yml
Normal file
@@ -0,0 +1,44 @@
|
||||
# полный реферерс тут
|
||||
# https://docs.gitlab.com/ee/ci/yaml/index.html
|
||||
# а тут доступные переменные
|
||||
# https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
|
||||
|
||||
image: docker:20.10.16
|
||||
|
||||
variables:
|
||||
REGISTRY: hub.bildme.ru
|
||||
IMAGE_NAME: $REGISTRY/$CI_PROJECT_PATH:latest
|
||||
VERSION: 0.0.1
|
||||
|
||||
stages:
|
||||
- build
|
||||
- deploy
|
||||
|
||||
build_main:
|
||||
stage: build
|
||||
variables:
|
||||
DOCKER_BASEIMAGE: golang:latest
|
||||
before_script:
|
||||
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $REGISTRY
|
||||
script:
|
||||
- docker build --pull --build-arg DOCKER_BASEIMAGE=${DOCKER_BASEIMAGE} -build-arg VERSION=${VERSION} -t $IMAGE_NAME .
|
||||
- docker push $IMAGE_NAME
|
||||
tags:
|
||||
- docker
|
||||
|
||||
deploy_prod:
|
||||
image: hub.realmanual.ru/pub/openssh-client:latest
|
||||
stage: deploy
|
||||
variables:
|
||||
DOCKER_SERVER: 192.168.9.199
|
||||
before_script:
|
||||
- eval $(ssh-agent -s)
|
||||
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
|
||||
- mkdir -p ~/.ssh
|
||||
- chmod 700 ~/.ssh
|
||||
- ssh-keyscan ${DOCKER_SERVER} >> ~/.ssh/known_hosts
|
||||
- chmod 644 ~/.ssh/known_hosts
|
||||
script:
|
||||
- ssh root@${DOCKER_SERVER} "docker rm -f main-go; docker pull hub.bildme.ru/firstgroup/go-site && docker run --rm --name main-go -p 3000:3000 hub.bildme.ru/firstgroup/go-site:latest"
|
||||
tags:
|
||||
- docker
|
21
ci/Dockerfile
Normal file
21
ci/Dockerfile
Normal file
@@ -0,0 +1,21 @@
|
||||
ARG DOCKER_BASEIMAGE
|
||||
FROM ${DOCKER_BASEIMAGE}
|
||||
|
||||
LABEL maintainer="${DOCKER_MAINTAINER:-vasyakrg@gmail.com}"
|
||||
|
||||
ADD ./app /app/
|
||||
WORKDIR /app/
|
||||
|
||||
ARG VERSION=0.0.1
|
||||
ENV VERSION=${VERSION}
|
||||
|
||||
RUN CGO_ENABLED=0 GOOS=linux GO111MODULE=auto go build -a -ldflags="-X 'main.Version=v${VERSION}'" -installsuffix cgo -o main .
|
||||
|
||||
|
||||
FROM alpine
|
||||
ENV LANGUAGE="ru"
|
||||
COPY --from=0 /app/ /
|
||||
RUN apk add --no-cache ca-certificates &&\
|
||||
chmod +x main
|
||||
|
||||
CMD [ "./main" ]
|
24
ci/app/main.go
Normal file
24
ci/app/main.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("<h1>Hello World!</h1>"))
|
||||
}
|
||||
|
||||
func main() {
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = "3000"
|
||||
}
|
||||
|
||||
fmt.Print("\nim run in http://127.0.0.1:", port)
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/", indexHandler)
|
||||
http.ListenAndServe(":"+port, mux)
|
||||
}
|
4
ci/docker-run.sh
Executable file
4
ci/docker-run.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
docker pull hub.bildme.ru/firstgroup/go-site:latest
|
||||
docker run --rm --name main-go -p 3000:3000 hub.bildme.ru/firstgroup/go-site:latest
|
Reference in New Issue
Block a user