Change ci-cd
This commit is contained in:
parent
d4cc0bb963
commit
1bcada3008
9 changed files with 76 additions and 122 deletions
|
@ -1,85 +1,15 @@
|
|||
variables:
|
||||
LATEST_IMAGE: '$CI_REGISTRY_IMAGE:latest'
|
||||
DOCKER_VERSION: '24.0.2'
|
||||
GOLANG_VERSION: '1.20'
|
||||
NODE_VERSION: '18'
|
||||
ALPINE_VERSION: '3'
|
||||
DEBIAN_VERSION: '12'
|
||||
TELEPORT_VERSION: '13.1.1'
|
||||
|
||||
image: docker:$DOCKER_VERSION-git
|
||||
|
||||
stages:
|
||||
- test
|
||||
- build
|
||||
- analyse
|
||||
- deploy
|
||||
|
||||
include:
|
||||
- local: .gitlab/_common.gitlab-ci.yml
|
||||
- local: .gitlab/_rules.gitlab-ci.yml
|
||||
- local: /.gitlab/test.gitlab-ci.yml
|
||||
- local: /.gitlab/build.gitlab-ci.yml
|
||||
- local: /.gitlab/deploy.gitlab-ci.yml
|
||||
- template: Jobs/Secret-Detection.gitlab-ci.yml
|
||||
- template: Jobs/Container-Scanning.gitlab-ci.yml
|
||||
|
||||
secret_detection:
|
||||
rules: !reference [.rules:default, rules]
|
||||
|
||||
unit_tests:
|
||||
rules: !reference [.rules:default, rules]
|
||||
stage: test
|
||||
image: golang:$GOLANG_VERSION-alpine
|
||||
extends:
|
||||
- .go-cache
|
||||
script:
|
||||
- go install gotest.tools/gotestsum@latest
|
||||
- gotestsum --junitfile report.xml --format testname -- ./... -coverprofile=profile.cov
|
||||
- go tool cover -func profile.cov
|
||||
coverage: '/\(statements\)(?:\s+)?(\d+(?:\.\d+)?%)/'
|
||||
artifacts:
|
||||
when: always
|
||||
reports:
|
||||
junit: report.xml
|
||||
|
||||
build_release:
|
||||
rules: !reference [.rules:release, rules]
|
||||
stage: build
|
||||
extends: .login_registry
|
||||
services:
|
||||
- name: docker:$DOCKER_VERSION-dind
|
||||
alias: docker
|
||||
variables:
|
||||
DOCKER_BUILDKIT: '1'
|
||||
DOCKER_TLS_CERTDIR: '/certs'
|
||||
CURRENT_IMAGE: '$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG'
|
||||
GO_BUILDER_IMAGE: '$CI_REGISTRY_IMAGE:go-builder'
|
||||
NODE_BUILDER_IMAGE: '$CI_REGISTRY_IMAGE:node-builder'
|
||||
LOGO_BUILDER_IMAGE: '$CI_REGISTRY_IMAGE:logo'
|
||||
script:
|
||||
- apk add bash
|
||||
- .gitlab/build_image.sh
|
||||
- docker push $CURRENT_IMAGE
|
||||
- docker push $LATEST_IMAGE
|
||||
|
||||
container_scanning:
|
||||
rules: !reference [.rules:release, rules]
|
||||
stage: analyse
|
||||
variables:
|
||||
GIT_STRATEGY: fetch
|
||||
CS_IMAGE: $LATEST_IMAGE
|
||||
CS_DOCKERFILE_PATH: docker/Dockerfile
|
||||
|
||||
deploy_release:
|
||||
rules: !reference [.rules:release, rules]
|
||||
stage: deploy
|
||||
image: debian:${DEBIAN_VERSION}-slim
|
||||
id_tokens:
|
||||
TBOT_GITLAB_JWT:
|
||||
aud: tp.fhoss.de
|
||||
script:
|
||||
- apt-get update && apt-get install curl -y
|
||||
- cd /tmp
|
||||
- 'curl -O https://cdn.teleport.dev/teleport-v${TELEPORT_VERSION}-linux-amd64-bin.tar.gz'
|
||||
- tar -xvf teleport-v${TELEPORT_VERSION}-linux-amd64-bin.tar.gz
|
||||
- ./teleport/install
|
||||
- 'tbot start --token=gitlab --destination-dir=/tmp/tbot-user --data-dir=/tmp/tbot-data --auth-server=tp.fhoss.de:443 --join-method=gitlab --oneshot'
|
||||
- 'tsh -i /tmp/tbot-user/identity --proxy tp.fhoss.de:443 ssh bot@benelli "docker compose -f /opt/docker/home/docker-compose.yml up -d --pull always"'
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
variables:
|
||||
LATEST_IMAGE: '$CI_REGISTRY_IMAGE:latest'
|
||||
DOCKER_VERSION: '24.0.2'
|
||||
GOLANG_VERSION: '1.20'
|
||||
NODE_VERSION: '18'
|
||||
ALPINE_VERSION: '3'
|
||||
DEBIAN_VERSION: '12'
|
||||
TELEPORT_VERSION: '13.1.1'
|
||||
|
||||
image: docker:$DOCKER_VERSION-git
|
||||
|
||||
.login_registry:
|
||||
before_script:
|
||||
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
|
||||
|
|
24
.gitlab/build.gitlab-ci.yml
Normal file
24
.gitlab/build.gitlab-ci.yml
Normal file
|
@ -0,0 +1,24 @@
|
|||
build_release:
|
||||
rules: !reference [.rules:release, rules]
|
||||
stage: build
|
||||
extends: .login_registry
|
||||
services:
|
||||
- name: docker:$DOCKER_VERSION-dind
|
||||
alias: docker
|
||||
variables:
|
||||
DOCKER_TLS_CERTDIR: '/certs'
|
||||
CURRENT_IMAGE: '$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG'
|
||||
script:
|
||||
- >
|
||||
docker build .
|
||||
--file docker/Dockerfile
|
||||
--build-arg GOLANG_VERSION=$GOLANG_VERSION
|
||||
--build-arg NODE_VERSION=$NODE_VERSION
|
||||
--build-arg ALPINE_VERSION=$ALPINE_VERSION
|
||||
--build-arg APP_VERSION=$CI_COMMIT_TAG
|
||||
--build-arg BUILD_TIME=$CI_JOB_STARTED_AT
|
||||
--tag $CURRENT_IMAGE
|
||||
--tag $LATEST_IMAGE
|
||||
- docker inspect $CURRENT_IMAGE
|
||||
- docker push $CURRENT_IMAGE
|
||||
- docker push $LATEST_IMAGE
|
|
@ -1,41 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
args=(
|
||||
--file docker/Dockerfile
|
||||
--build-arg GOLANG_VERSION=${GOLANG_VERSION}
|
||||
--build-arg NODE_VERSION=${NODE_VERSION}
|
||||
--build-arg ALPINE_VERSION=${ALPINE_VERSION}
|
||||
--build-arg BUILDKIT_INLINE_CACHE=1
|
||||
)
|
||||
|
||||
docker pull ${GO_BUILDER_IMAGE} || true
|
||||
docker build . ${args[@]} \
|
||||
--target goBuilder \
|
||||
--cache-from ${GO_BUILDER_IMAGE} \
|
||||
--tag ${GO_BUILDER_IMAGE}
|
||||
docker push ${GO_BUILDER_IMAGE}
|
||||
|
||||
docker pull ${NODE_BUILDER_IMAGE} || true
|
||||
docker build . ${args[@]} \
|
||||
--target nodeBuilder \
|
||||
--cache-from ${NODE_BUILDER_IMAGE} \
|
||||
--tag ${NODE_BUILDER_IMAGE}
|
||||
docker push ${NODE_BUILDER_IMAGE}
|
||||
|
||||
docker pull ${LOGO_BUILDER_IMAGE} || true
|
||||
docker build . ${args[@]} \
|
||||
--target logo \
|
||||
--cache-from ${LOGO_BUILDER_IMAGE} \
|
||||
--tag ${LOGO_BUILDER_IMAGE}
|
||||
docker push ${LOGO_BUILDER_IMAGE}
|
||||
|
||||
docker pull ${LATEST_IMAGE} || true
|
||||
docker build . ${args[@]} \
|
||||
--cache-from ${GO_BUILDER_IMAGE} \
|
||||
--cache-from ${NODE_BUILDER_IMAGE} \
|
||||
--cache-from ${LOGO_BUILDER_IMAGE} \
|
||||
--cache-from ${LATEST_IMAGE} \
|
||||
--build-arg VERSION=${CI_COMMIT_TAG} \
|
||||
--build-arg BUILDTIME=${CI_JOB_STARTED_AT} \
|
||||
--tag ${CURRENT_IMAGE} \
|
||||
--tag ${LATEST_IMAGE}
|
15
.gitlab/deploy.gitlab-ci.yml
Normal file
15
.gitlab/deploy.gitlab-ci.yml
Normal file
|
@ -0,0 +1,15 @@
|
|||
deploy_release:
|
||||
rules: !reference [.rules:release, rules]
|
||||
stage: deploy
|
||||
image: debian:${DEBIAN_VERSION}-slim
|
||||
id_tokens:
|
||||
TBOT_GITLAB_JWT:
|
||||
aud: tp.fhoss.de
|
||||
script:
|
||||
- apt-get update && apt-get install curl -y
|
||||
- cd /tmp
|
||||
- 'curl -O https://cdn.teleport.dev/teleport-v${TELEPORT_VERSION}-linux-amd64-bin.tar.gz'
|
||||
- tar -xvf teleport-v${TELEPORT_VERSION}-linux-amd64-bin.tar.gz
|
||||
- ./teleport/install
|
||||
- 'tbot start --token=gitlab --destination-dir=/tmp/tbot-user --data-dir=/tmp/tbot-data --auth-server=tp.fhoss.de:443 --join-method=gitlab --oneshot'
|
||||
- 'tsh -i /tmp/tbot-user/identity --proxy tp.fhoss.de:443 ssh bot@benelli "docker compose -f /opt/docker/home/docker-compose.yml up -d --pull always"'
|
15
.gitlab/test.gitlab-ci.yml
Normal file
15
.gitlab/test.gitlab-ci.yml
Normal file
|
@ -0,0 +1,15 @@
|
|||
unit_tests:
|
||||
rules: !reference [.rules:default, rules]
|
||||
stage: test
|
||||
image: golang:$GOLANG_VERSION-alpine
|
||||
extends:
|
||||
- .go-cache
|
||||
script:
|
||||
- go install gotest.tools/gotestsum@latest
|
||||
- gotestsum --junitfile report.xml --format testname -- ./... -coverprofile=profile.cov
|
||||
- go tool cover -func profile.cov
|
||||
coverage: '/\(statements\)(?:\s+)?(\d+(?:\.\d+)?%)/'
|
||||
artifacts:
|
||||
when: always
|
||||
reports:
|
||||
junit: report.xml
|
|
@ -39,9 +39,9 @@ COPY --from=goBuilder /app/internal/bookmarks/config.yaml .internal/bookmarks/co
|
|||
COPY --from=goBuilder /app/godash .
|
||||
|
||||
# Envs
|
||||
ARG VERSION
|
||||
ENV VERSION=$VERSION
|
||||
ARG BUILDTIME
|
||||
ENV BUILDTIME=$BUILDTIME
|
||||
ARG APP_VERSION
|
||||
ENV APP_VERSION=$APP_VERSION
|
||||
ARG BUILD_TIME
|
||||
ENV BUILD_TIME=$BUILD_TIME
|
||||
|
||||
ENTRYPOINT ["/app/entrypoint.sh"]
|
||||
|
|
|
@ -13,5 +13,5 @@ RUN go install github.com/cosmtrek/air@latest
|
|||
COPY ./.air.toml .
|
||||
|
||||
# Envs
|
||||
ENV VERSION=v0.0.1-dev
|
||||
ENV BUILDTIME=2023-04-05T20:48:07Z
|
||||
ENV APP_VERSION=v0.0.1-dev
|
||||
ENV BUILD_TIME=2023-04-05T20:48:07Z
|
||||
|
|
|
@ -18,12 +18,12 @@
|
|||
transition: opacity linear 0.15s;
|
||||
}
|
||||
</style>
|
||||
<link rel="stylesheet" href="/static/css/style.css?v={{ env "VERSION" }}" />
|
||||
<link rel="stylesheet" href="/static/css/style.css?v={{ env "APP_VERSION" }}" />
|
||||
{{ block "style". }}{{ end }}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="absolute top-2 right-3 text-xs text-gray-500">{{ env "VERSION" }}</div>
|
||||
<div class="absolute top-2 right-3 text-xs text-gray-500">{{ env "APP_VERSION" }}</div>
|
||||
<div class="p-4 sm:p-6 lg:p-8 xl:container xl:py-12">{{ block "content" . }}{{ end }}</div>
|
||||
{{ block "js". }}{{ end }}
|
||||
</body>
|
||||
|
|
Loading…
Reference in a new issue