Skip to content

Commit

Permalink
Make container images configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Ondra Machacek <[email protected]>
  • Loading branch information
machacekondra committed Oct 8, 2024
1 parent 6012da3 commit 0a251ca
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Containerfile.agent
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM docker.io/library/alpine as ui
FROM registry.access.redhat.com/ubi9/ubi as ui

WORKDIR /app
RUN mkdir /app/www && \
wget -O /tmp/agent-latest.tgz https://github.com/kubev2v/migration-planner-ui/releases/download/latest/agent-latest.tgz && \
curl -Lo /tmp/agent-latest.tgz https://github.com/kubev2v/migration-planner-ui/releases/download/latest/agent-latest.tgz && \
tar xf /tmp/agent-latest.tgz -C /app/www

# Builder container
Expand Down
8 changes: 3 additions & 5 deletions Containerfile.api
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Builder container
FROM registry.access.redhat.com/ubi9/go-toolset as iso
WORKDIR /iso
RUN curl -o /iso/rhcos-live.x86_64.iso https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/latest/rhcos-live.x86_64.iso

FROM registry.access.redhat.com/ubi9/go-toolset as builder

WORKDIR /app
RUN curl -o /app/rhcos-live.x86_64.iso https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/latest/rhcos-live.x86_64.iso

COPY go.mod go.sum ./
RUN go mod download

Expand All @@ -20,7 +18,7 @@ WORKDIR /app

COPY /data /app/data/
COPY --from=builder /planner-api /app/
COPY --from=iso /iso/rhcos-live.x86_64.iso /app/
COPY --from=builder /app/rhcos-live.x86_64.iso /app/

# Use non-root user
RUN chown -R 1001:0 /app
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ VERBOSE ?= false
MIGRATION_PLANNER_AGENT_IMAGE ?= quay.io/kubev2v/migration-planner-agent
MIGRATION_PLANNER_COLLECTOR_IMAGE ?= quay.io/kubev2v/migration-planner-collector
MIGRATION_PLANNER_API_IMAGE ?= quay.io/kubev2v/migration-planner-api
MIGRATION_PLANNER_UI_IMAGE ?= quay.io/kubev2v/migration-planner-ui

SOURCE_GIT_TAG ?=$(shell git describe --always --long --tags --abbrev=7 --match 'v[0-9]*' || echo 'v0.0.0-unknown-$(SOURCE_GIT_COMMIT)')
SOURCE_GIT_TREE_STATE ?=$(shell ( ( [ ! -d ".git/" ] || git diff --quiet ) && echo 'clean' ) || echo 'dirty')
Expand Down Expand Up @@ -85,6 +86,8 @@ push-containers: build-containers
podman push $(MIGRATION_PLANNER_AGENT_IMAGE):latest

deploy-on-openshift:
sed 's|@MIGRATION_PLANNER_API_IMAGE@|$(MIGRATION_PLANNER_API_IMAGE)|g' deploy/k8s/migration-planner.yaml.template > deploy/k8s/migration-planner.yaml
sed 's|@MIGRATION_PLANNER_UI_IMAGE@|$(MIGRATION_PLANNER_UI_IMAGE)|g' deploy/k8s/migration-planner-ui.yaml.template > deploy/k8s/migration-planner-ui.yaml
oc apply -f 'deploy/k8s/*-service.yaml'
oc apply -f 'deploy/k8s/*-secret.yaml'
oc create route edge planner --service=migration-planner-ui || true
Expand Down
16 changes: 10 additions & 6 deletions data/config.ign.template
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,26 @@ storage:
name: core
group:
name: core
- path: /home/core/.config/systemd/user/planner-setup.service
- path: /home/core/.config/containers/systemd/planner-setup.container
mode: 0644
contents:
inline: |
[Unit]
Description=Prepare data volume for the container
Before=planner-agent.service

[Service]
ExecStart=/usr/bin/podman run --rm -v planner.volume:/agent -v /home/core/vol:/mnt:Z alpine sh -c "cp -r /mnt/* /agent/ && chmod -R a+rwx /agent"
[Container]
Image=registry.access.redhat.com/ubi9/ubi-micro
Exec=sh -c "cp -r /mnt/* /agent/ && chmod -R a+rwx /agent"
Volume=planner.volume:/agent
Volume=/home/core/vol:/mnt:Z

[Service]
Type=oneshot
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
WantedBy=multi-user.target default.target
- path: /home/core/.config/containers/systemd/planner-agent.container
mode: 0644
contents:
Expand All @@ -103,7 +107,7 @@ storage:
Wants=planner-setup.service

[Container]
Image=quay.io/kubev2v/migration-planner-agent
Image=@MIGRATION_PLANNER_AGENT_IMAGE@
ContainerName=planner-agent
AutoUpdate=registry
Exec= -config /agent/config.yaml
Expand Down Expand Up @@ -140,7 +144,7 @@ storage:
Wants=planner-agent-opa.service

[Container]
Image=quay.io/kubev2v/migration-planner-collector
Image=@MIGRATION_PLANNER_COLLECTOR_IMAGE@
ContainerName=migration-planner-collector
AutoUpdate=registry
Exec=/vol/data/credentials.json /vol/data/inventory.json
Expand Down
2 changes: 1 addition & 1 deletion deploy/k8s/migration-planner-ui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:
spec:
containers:
- name: migration-planner-ui
image: quay.io/machacekondra/migration-planner-ui
image: quay.io/kubev2v/migration-planner-ui
imagePullPolicy: Always
ports:
- containerPort: 8080
Expand Down
21 changes: 21 additions & 0 deletions deploy/k8s/migration-planner-ui.yaml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
kind: Deployment
apiVersion: apps/v1
metadata:
name: migration-planner-ui
spec:
replicas: 1
selector:
matchLabels:
app: migration-planner-ui
template:
metadata:
labels:
app: migration-planner-ui
spec:
containers:
- name: migration-planner-ui
image: @MIGRATION_PLANNER_UI_IMAGE@
imagePullPolicy: Always
ports:
- containerPort: 8080
restartPolicy: Always
57 changes: 57 additions & 0 deletions deploy/k8s/migration-planner.yaml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: migration-planner
spec:
selector:
matchLabels:
app: migration-planner
replicas: 1
template:
metadata:
labels:
app: migration-planner
spec:
containers:
- name: migration-planner
resources:
limits:
cpu: 500m
memory: 2000Mi
requests:
cpu: 300m
memory: 400Mi
image: @MIGRATION_PLANNER_API_IMAGE@
imagePullPolicy: Always
ports:
- containerPort: 3443
livenessProbe:
httpGet:
path: /health
port: 3443
initialDelaySeconds: 30
env:
- name: CONFIG_SERVER
valueFrom:
secretKeyRef:
name: migration-planner-secret
key: config_server
volumeMounts:
- name: migration-planner-config
mountPath: "/.migration-planner/config.yaml"
subPath: config.yaml
readOnly: true
serviceAccountName: migration-planner
volumes:
- name: migration-planner-config
secret:
secretName: migration-planner-rds
optional: true
items:
- key: config.yaml
path: config.yaml
---
kind: ServiceAccount
apiVersion: v1
metadata:
name: migration-planner
2 changes: 2 additions & 0 deletions internal/image/ova.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ func (o *Ova) generateIgnition() (string, error) {

butaneContent := strings.Replace(string(butaneTemplate), "@CONFIG_ID@", o.Id.String(), -1)
butaneContent = strings.Replace(butaneContent, "@CONFIG_SERVER@", util.GetEnv("CONFIG_SERVER", "http://127.0.0.1:7443"), -1)
butaneContent = strings.Replace(butaneContent, "@MIGRATION_PLANNER_COLLECTOR_IMAGE@", util.GetEnv("MIGRATION_PLANNER_COLLECTOR_IMAGE", "quay.io/kubev2v/migration-planner-collector"), -1)
butaneContent = strings.Replace(butaneContent, "@MIGRATION_PLANNER_AGENT_IMAGE@", util.GetEnv("MIGRATION_PLANNER_AGENT_IMAGE", "quay.io/kubev2v/migration-planner-agent"), -1)

dataOut, _, err := config.TranslateBytes([]byte(butaneContent), common.TranslateBytesOptions{})
if err != nil {
Expand Down

0 comments on commit 0a251ca

Please sign in to comment.