Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Egna datormiljön
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TDP003 - Projekt
Egna datormiljön
Commits
0d9cad89
Commit
0d9cad89
authored
5 months ago
by
Oliwer Mattsson
Browse files
Options
Downloads
Plain Diff
Laddade upp "ren" version av repo inför munta.
parents
70484ffa
9cca6c99
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
MyPortfolio/.dockerignore
+2
-1
2 additions, 1 deletion
MyPortfolio/.dockerignore
MyPortfolio/.gitlab-ci.yml
+167
-0
167 additions, 0 deletions
MyPortfolio/.gitlab-ci.yml
MyPortfolio/Dockerfile
+2
-1
2 additions, 1 deletion
MyPortfolio/Dockerfile
with
171 additions
and
2 deletions
MyPortfolio/.dockerignore
+
2
−
1
View file @
0d9cad89
**/.git
**/_pycache_
**/__pycache__
This diff is collapsed.
Click to expand it.
MyPortfolio/.gitlab-ci.yml
0 → 100644
+
167
−
0
View file @
0d9cad89
stages
:
-
build
-
deploy
docker_build
:
stage
:
build
image
:
quay.io/podman/stable
only
:
-
master
-
main
script
:
-
podman build --tag $CI_REGISTRY_IMAGE:latest --file $CI_PROJECT_DIR/Dockerfile $CI_PROJECT_DIR
-
podman push --creds "${CI_REGISTRY_USER}:${CI_JOB_TOKEN}" $CI_REGISTRY_IMAGE:latest "docker://${CI_REGISTRY_IMAGE}"
kube_deploy
:
stage
:
deploy
image
:
bitnami/kubectl
environment
:
name
:
production
url
:
http://${CI_PROJECT_PATH_SLUG}.kubernetes-public.it.liu.se/
only
:
-
master
-
main
script
:
-
|
if [[ "$CI_DEPLOY_USER" == "" ]]
then
echo "Du har inte skapat ett deploy token i GitLab!"
exit 1
fi
-
CONTEXT=${CI_PROJECT_PATH_SLUG%-*}
-
|
# Ensures that the configuration still works in case we don't have access to a context
if kubectl config use-context ${CONTEXT}/infrastructure:${CONTEXT}
then
kubectl config set-context --current --namespace=${CI_PROJECT_PATH_SLUG}
fi
-
CI_DEPLOY_AUTH=$(echo -n $CI_DEPLOY_USER:$CI_DEPLOY_PASSWORD | base64)
-
|
# Deploy environment with kubectl apply
kubectl apply -f - <<EOF
apiVersion: v1
kind: Secret
metadata:
name: gitlab-docker-creds
type: kubernetes.io/dockerconfigjson
stringData:
.dockerconfigjson: |
{
"auths" : {
"${CI_REGISTRY}" : {
"username" : "${CI_DEPLOY_USER}",
"password" : "${CI_DEPLOY_PASSWORD}",
"auth" : "${CI_DEPLOY_AUTH}"
}
}
}
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
se.liu.gitlab/commit: $CI_COMMIT_SHA
app.gitlab.com/app: $CI_PROJECT_PATH_SLUG
app.gitlab.com/env: $CI_ENVIRONMENT_SLUG
labels:
app: ${CI_PROJECT_PATH_SLUG}
environment: $CI_ENVIRONMENT_SLUG
name: ${CI_PROJECT_PATH_SLUG}
spec:
replicas: 1
revisionHistoryLimit: 1
selector:
matchLabels:
app: ${CI_PROJECT_PATH_SLUG}
environment: $CI_ENVIRONMENT_SLUG
template:
metadata:
annotations:
app.gitlab.com/app: $CI_PROJECT_PATH_SLUG
app.gitlab.com/env: $CI_ENVIRONMENT_SLUG
labels:
commit: $CI_COMMIT_SHA
app: ${CI_PROJECT_PATH_SLUG}
environment: $CI_ENVIRONMENT_SLUG
spec:
imagePullSecrets:
- name: gitlab-docker-creds
containers:
- env:
- name: http_proxy
value: http://squid-proxy.kube-system.svc:3128/
- name: https_proxy
value: http://squid-proxy.kube-system.svc:3128/
command: ["flask", "run", "-h", "0", "-p", "3000"]
image: $CI_REGISTRY_IMAGE:latest
imagePullPolicy: Always
name: ${CI_PROJECT_PATH_SLUG}
ports:
- containerPort: 3000
protocol: TCP
readinessProbe:
tcpSocket:
port: 3000
resources:
limits:
cpu: 100m
memory: 80Mi
requests:
cpu: 15m
memory: 42Mi
---
apiVersion: v1
kind: Service
metadata:
labels:
commit: $CI_COMMIT_SHA
app: ${CI_PROJECT_PATH_SLUG}
environment: $CI_ENVIRONMENT_SLUG
name: ${CI_PROJECT_PATH_SLUG}
spec:
ports:
- name: web
port: 80
protocol: TCP
targetPort: 3000
selector:
app: ${CI_PROJECT_PATH_SLUG}
type: ClusterIP
EOF
-
|
[ "$CI_ENVIRONMENT_SLUG" == "production" ] && echo "Publicerar till https://$CI_PROJECT_PATH_SLUG.kubernetes-public.it.liu.se/"
-
|
# Deploy production ingress only on the production environment
[ "$CI_ENVIRONMENT_SLUG" == "production" ] && kubectl apply -f - <<EOF || true
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ${CI_PROJECT_PATH_SLUG}
annotations:
kubernetes.io/ingress.class: nginx-public
kubernetes.io/tls-acme: "true"
traefik.ingress.kubernetes.io/router.middlewares: traefik-https-redirect@kubernetescrd
labels:
app: ${CI_PROJECT_PATH_SLUG}
environment: $CI_ENVIRONMENT_SLUG
spec:
rules:
- host: ${CI_PROJECT_PATH_SLUG}.kubernetes-public.it.liu.se
http:
paths:
- backend:
service:
name: ${CI_PROJECT_PATH_SLUG}
port:
number: 80
path: /
pathType: Prefix
tls:
- hosts:
- '*.kubernetes-public.it.liu.se'
secretName: portfolio-public-tls
EOF
variables
:
GIT_STRATEGY
:
none
This diff is collapsed.
Click to expand it.
MyPortfolio/Dockerfile
+
2
−
1
View file @
0d9cad89
...
...
@@ -8,4 +8,5 @@ RUN pip install flask
ADD
. $APP_HOME/
ENV
FLASK_APP=myFlaskProject.py
CMD
flask run -h 0 -p 3000
CMD
flask run -h 0 -p 5000
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment