Scheduled job for Docker cleanup

This commit is contained in:
Aarni Halinen
2022-10-24 21:58:39 +03:00
parent f67ce55d60
commit 52a83b9336
+60 -3
View File
@@ -5,10 +5,13 @@ stages:
- test
- publish
- deploy
- cleanup
install:
image: node:14
stage: setup
only:
- pushes
script:
- npm ci
artifacts:
@@ -19,6 +22,8 @@ install:
audit:
image: python:3.9
stage: audit
only:
- pushes
needs: []
before_script:
- pip install poetry==1.1.13
@@ -30,6 +35,8 @@ audit:
test:
image: python:3.9
stage: test
only:
- pushes
needs: []
services:
- postgres:12
@@ -51,6 +58,8 @@ test:
lint:py:
image: python:3.9
stage: lint
only:
- pushes
needs: []
script:
- pip install black==22.3.0
@@ -59,6 +68,8 @@ lint:py:
lint:js:
image: node:14
stage: lint
only:
- pushes
needs: ["install"]
script:
- npm run lint:js
@@ -66,13 +77,15 @@ lint:js:
lint:md:
image: node:14
stage: lint
only:
- pushes
needs: ["install"]
script:
- npm run lint:md
publish:
stage: publish
image: docker:stable
stage: publish
needs: ["test", "lint:py", "lint:js", "lint:md"]
services:
- docker:stable-dind
@@ -86,8 +99,8 @@ publish:
- docker push "$IMAGE_NAME"
deploy:dev:
stage: deploy
image: docker:stable
stage: deploy
only:
- develop
environment:
@@ -128,4 +141,48 @@ deploy:production:
script:
- docker stack deploy --with-registry-auth -c stack-compose.yml "$SERVICE_NAME"
after_script:
- docker logout "$CI_REGISTRY"
- docker logout "$CI_REGISTRY"
docker_prune:dev:
image: docker:stable
stage: cleanup
only:
- schedules
environment:
name: dev
url: http://api.dev.sahkoinsinoorikilta.fi
variables:
DOCKER_HOST: $DEV_CI_DOCKER_HOST
DOCKER_TLS_VERIFY: 1
before_script:
- mkdir -p ~/.docker
- echo "$DEV_TLSCACERT" > ~/.docker/ca.pem
- echo "$DEV_TLSCERT" > ~/.docker/cert.pem
- echo "$DEV_TLSKEY" > ~/.docker/key.pem
- docker login -u gitlab-ci-token -p "$CI_BUILD_TOKEN" "$CI_REGISTRY"
script:
- docker system prune
after_script:
- docker logout "$CI_REGISTRY"
docker_prune:prod:
image: docker:stable
stage: cleanup
only:
- schedules
environment:
name: production
url: https://api.sahkoinsinoorikilta.fi
variables:
DOCKER_HOST: $CI_DOCKER_HOST
DOCKER_TLS_VERIFY: 1
before_script:
- mkdir -p ~/.docker
- echo "$TLSCACERT" > ~/.docker/ca.pem
- echo "$TLSCERT" > ~/.docker/cert.pem
- echo "$TLSKEY" > ~/.docker/key.pem
- docker login -u gitlab-ci-token -p "$CI_BUILD_TOKEN" "$CI_REGISTRY"
script:
- docker system prune
after_script:
- docker logout "$CI_REGISTRY"