9iron/.gitlab-ci.yml

73 lines
2.0 KiB
YAML
Raw Normal View History

2021-03-20 13:34:56 -05:00
#
# This guy is awesome: https://dev.to/bzinoun/gitlab-ci-to-build-and-push-containers-to-registry-538a
#
image: docker:latest
variables:
# DinD's vfs driver is pretty intensive; this is less so
DOCKER_DRIVER: overlay2
CI_HUB_USERNAME: rehashedsalt
stages:
- build
- test
2021-03-20 13:34:56 -05:00
- push
services:
- docker:dind
before_script:
- echo -n "$CI_LOGIN_PASSWORD" | docker login -u "$CI_LOGIN_USERNAME" --password-stdin
- docker version
- docker info
after_script:
- docker logout hub.docker.com
# BUILD
2021-03-20 13:34:56 -05:00
Build:
stage: build
script:
- docker pull $CI_HUB_USERNAME/$CI_PROJECT_NAME:latest || true
2021-03-20 14:20:43 -05:00
- docker buildx create --use
2021-03-20 13:34:56 -05:00
- >
2021-03-20 14:20:43 -05:00
docker buildx build
2021-03-20 13:34:56 -05:00
--pull
2021-03-20 14:20:43 -05:00
--platform linux/amd64,linux/arm64
2021-03-20 13:34:56 -05:00
--cache-from $CI_HUB_USERNAME/$CI_PROJECT_NAME:latest
--tag $CI_HUB_USERNAME/$CI_PROJECT_NAME:$CI_COMMIT_SHORT_SHA
.
- docker push $CI_HUB_USERNAME/$CI_PROJECT_NAME:$CI_COMMIT_SHORT_SHA
# TEST
Test_HTTP_200:
stage: test
script:
2021-03-20 14:17:37 -05:00
- apk add curl
- docker run -d -p 8889:80 $CI_HUB_USERNAME/$CI_PROJECT_NAME:$CI_COMMIT_SHORT_SHA
- curl localhost:8889 | grep -ie '200 OK'
- docker kill $(docker ps -q)
# PUSH
2021-03-20 13:34:56 -05:00
Push_When_Tag:
stage: push
only:
- tags
script:
- docker pull $CI_HUB_USERNAME/$CI_PROJECT_NAME:$CI_COMMIT_SHORT_SHA
- >
docker tag
$CI_HUB_USERNAME/$CI_PROJECT_NAME:$CI_COMMIT_SHORT_SHA
$CI_HUB_USERNAME/$CI_PROJECT_NAME:$CI_COMMIT_REF_NAME
- docker push $CI_HUB_USERNAME/$CI_PROJECT_NAME:$CI_COMMIT_REF_NAME
- >
docker tag
$CI_HUB_USERNAME/$CI_PROJECT_NAME:$CI_COMMIT_SHORT_SHA
$CI_HUB_USERNAME/$CI_PROJECT_NAME:latest
- docker push $CI_HUB_USERNAME/$CI_PROJECT_NAME:latest
Push_Bleeding:
2021-03-20 13:34:56 -05:00
stage: push
script:
- docker pull $CI_HUB_USERNAME/$CI_PROJECT_NAME:$CI_COMMIT_SHORT_SHA
- >
docker tag
$CI_HUB_USERNAME/$CI_PROJECT_NAME:$CI_COMMIT_SHORT_SHA
$CI_HUB_USERNAME/$CI_PROJECT_NAME:bleeding
2021-03-20 13:39:01 -05:00
- docker push $CI_HUB_USERNAME/$CI_PROJECT_NAME:bleeding