This commit is contained in:
2023-11-23 13:50:02 -06:00
parent b19c3bdf94
commit df1eb6fb89
5 changed files with 95 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
stages:
- build
- package
- publish
include:
- template: Security/Secret-Detection.gitlab-ci.yml
- project: 'developerdurp/yml'
ref: 'main'
file:
- 'jobs/docker.yml'
- 'jobs/version.yml'
secret_detection:
stage: .pre
rules:
- when: always
allow_failure: false
version:
extends: .version
stage: .pre
rules:
- when: always
build:
extends: .docker_build
stage: build
artifacts:
paths:
- $CI_PROJECT_DIR/package
needs:
- job: version
artifacts: true
upload:
extends: .docker_push_gitlab
stage: package
needs:
- job: version
artifacts: true
- job: build
artifacts: true
rules:
- if: $CI_COMMIT_BRANCH =~ '/^release/'
- if: $CI_COMMIT_BRANCH =~ 'main'
- when: never

8
scripts/docker/build.sh Normal file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
#%%MULTILINE_YAML_START
#Build Docker Container
mkdir $CI_PROJECT_DIR/packages
containername=$(echo "$PROJECT_NAME" | awk '{print tolower($0)}')
docker build -t $containername .
docker save -o $CI_PROJECT_DIR/packages/$containername.$VERSION.tar.gz $containername

4
scripts/docker/login.sh Normal file
View File

@@ -0,0 +1,4 @@
#!/usr/bin/env bash
#%%MULTILINE_YAML_START
#Docker Login
docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY/$CI_PROJECT_PATH

View File

@@ -0,0 +1,10 @@
#!/usr/bin/env bash
#%%MULTILINE_YAML_START
#Push container to gitlab
containername=$(echo "$PROJECT_NAME" | awk '{print tolower($0)}')
docker import $CI_PROJECT_DIR/packages/$containername.$VERSION.tar.gz $CI_REGISTRY/$CI_PROJECT_PATH:$VERSION
docker import $CI_PROJECT_DIR/packages/$containername.$VERSION.tar.gz $CI_REGISTRY/$CI_PROJECT_PATH:latest
docker push "$CI_REGISTRY/$CI_PROJECT_PATH:$VERSION"
docker push "$CI_REGISTRY/$CI_PROJECT_PATH:latest"

View File

@@ -10,3 +10,29 @@
script:
- ./scripts/docker-login.sh
- ./scripts/docker-build.sh
.docker_build:
image: registry.durp.info/docker:20.10.17
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
DOCKER_HOST: tcp://127.0.0.1:2375/
services:
- name: docker:dind
entrypoint: ["dockerd-entrypoint.sh", "--tls=false"]
script:
- ./scripts/docker/build.sh
.docker_push_gitlab:
image: registry.durp.info/docker:20.10.17
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
DOCKER_HOST: tcp://127.0.0.1:2375/
services:
- name: docker:dind
entrypoint: ["dockerd-entrypoint.sh", "--tls=false"]
script:
- ./scripts/docker/login.sh
- ./scripts/docker/push-gitlab.sh