Adding Docker autobuild
This commit is contained in:
parent
4ef15d2e32
commit
e49830f297
2 changed files with 60 additions and 0 deletions
54
.gitlab-ci.yml
Normal file
54
.gitlab-ci.yml
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
###############################################################
|
||||||
|
# Setting I use for cleaning up image tags #
|
||||||
|
# - Running cleanup every week #
|
||||||
|
# - Keeping 1 tag per image name matching : (?:v.\d+|dev) #
|
||||||
|
# - Removing tags older than 7 days matching the default : .* #
|
||||||
|
###############################################################
|
||||||
|
|
||||||
|
image: docker:stable
|
||||||
|
|
||||||
|
stages:
|
||||||
|
- build
|
||||||
|
- push
|
||||||
|
|
||||||
|
services:
|
||||||
|
- docker:dind
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- echo -n $CI_JOB_TOKEN | docker login -u gitlab-ci-token --password-stdin $CI_REGISTRY
|
||||||
|
|
||||||
|
Build:
|
||||||
|
stage: build
|
||||||
|
script:
|
||||||
|
- docker pull $CI_REGISTRY_IMAGE:latest || true
|
||||||
|
- >
|
||||||
|
docker build
|
||||||
|
--pull
|
||||||
|
--build-arg VCS_REF=$CI_COMMIT_SHA
|
||||||
|
--build-arg VCS_URL=$CI_PROJECT_URL
|
||||||
|
--cache-from $CI_REGISTRY_IMAGE:latest
|
||||||
|
--tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
|
||||||
|
.
|
||||||
|
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
|
||||||
|
|
||||||
|
Push latest:
|
||||||
|
variables:
|
||||||
|
GIT_STRATEGY: none
|
||||||
|
stage: push
|
||||||
|
only:
|
||||||
|
- main
|
||||||
|
script:
|
||||||
|
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
|
||||||
|
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:latest
|
||||||
|
- docker push $CI_REGISTRY_IMAGE:latest
|
||||||
|
|
||||||
|
Push tag:
|
||||||
|
variables:
|
||||||
|
GIT_STRATEGY: none
|
||||||
|
stage: push
|
||||||
|
only:
|
||||||
|
- tags
|
||||||
|
script:
|
||||||
|
- docker pull $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
|
||||||
|
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
|
||||||
|
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
|
6
Dockerfile
Normal file
6
Dockerfile
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
FROM python:3.9.5-slim
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
RUN pip install -r requirements.txt
|
||||||
|
|
||||||
|
CMD [ "python", "-u", "./main.py" ]
|
Reference in a new issue