Scheduled job for Docker cleanup

This commit is contained in:
Aarni Halinen
2022-10-24 21:58:39 +03:00
parent f67ce55d60
commit 52a83b9336
+59 -2
View File
@@ -5,10 +5,13 @@ stages:
- test - test
- publish - publish
- deploy - deploy
- cleanup
install: install:
image: node:14 image: node:14
stage: setup stage: setup
only:
- pushes
script: script:
- npm ci - npm ci
artifacts: artifacts:
@@ -19,6 +22,8 @@ install:
audit: audit:
image: python:3.9 image: python:3.9
stage: audit stage: audit
only:
- pushes
needs: [] needs: []
before_script: before_script:
- pip install poetry==1.1.13 - pip install poetry==1.1.13
@@ -30,6 +35,8 @@ audit:
test: test:
image: python:3.9 image: python:3.9
stage: test stage: test
only:
- pushes
needs: [] needs: []
services: services:
- postgres:12 - postgres:12
@@ -51,6 +58,8 @@ test:
lint:py: lint:py:
image: python:3.9 image: python:3.9
stage: lint stage: lint
only:
- pushes
needs: [] needs: []
script: script:
- pip install black==22.3.0 - pip install black==22.3.0
@@ -59,6 +68,8 @@ lint:py:
lint:js: lint:js:
image: node:14 image: node:14
stage: lint stage: lint
only:
- pushes
needs: ["install"] needs: ["install"]
script: script:
- npm run lint:js - npm run lint:js
@@ -66,13 +77,15 @@ lint:js:
lint:md: lint:md:
image: node:14 image: node:14
stage: lint stage: lint
only:
- pushes
needs: ["install"] needs: ["install"]
script: script:
- npm run lint:md - npm run lint:md
publish: publish:
stage: publish
image: docker:stable image: docker:stable
stage: publish
needs: ["test", "lint:py", "lint:js", "lint:md"] needs: ["test", "lint:py", "lint:js", "lint:md"]
services: services:
- docker:stable-dind - docker:stable-dind
@@ -86,8 +99,8 @@ publish:
- docker push "$IMAGE_NAME" - docker push "$IMAGE_NAME"
deploy:dev: deploy:dev:
stage: deploy
image: docker:stable image: docker:stable
stage: deploy
only: only:
- develop - develop
environment: environment:
@@ -129,3 +142,47 @@ deploy:production:
- docker stack deploy --with-registry-auth -c stack-compose.yml "$SERVICE_NAME" - docker stack deploy --with-registry-auth -c stack-compose.yml "$SERVICE_NAME"
after_script: 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"