Skip to content

Commit

Permalink
Merge branch 'main' into enable-importing-non-external-user-models
Browse files Browse the repository at this point in the history
  • Loading branch information
kian99 committed Aug 28, 2023
2 parents bd23c1b + 53823aa commit e8b585d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
22 changes: 7 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
# syntax=docker/dockerfile:1.3.1
FROM ubuntu:20.04 AS build
SHELL ["/bin/bash", "-c"]
ENV GVM_VERSION=master
COPY ./go.mod ./go.mod
RUN apt-get update && \
apt-get -y install gcc bison binutils make git gcc curl build-essential mercurial ca-certificates
RUN bash < <(curl -SL -v https://raw.githubusercontent.com/moovweb/gvm/${GVM_VERSION}/binscripts/gvm-installer) && \
source /root/.gvm/scripts/gvm && \
gvm install go$(cat go.mod | sed -n "/^go/p" | cut -d ' ' -f 2) -B && \
gvm use go$(cat go.mod | sed -n "/^go/p" | cut -d ' ' -f 2) --default


FROM build as build-env
FROM ubuntu:20.04 as build-env
ARG GIT_COMMIT
ARG VERSION
ARG GO_VERSION
WORKDIR /usr/src/jimm
SHELL ["/bin/bash", "-c"]
COPY . .
RUN apt update && apt install wget gcc -y
RUN wget -L "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz"
RUN tar -C /usr/local -xzf "go${GO_VERSION}.linux-amd64.tar.gz"
ENV PATH="${PATH}:/usr/local/go/bin"
RUN echo "${GIT_COMMIT}" | tee ./version/commit.txt
RUN echo "${VERSION}" | tee ./version/version.txt
RUN --mount=type=ssh source /root/.gvm/scripts/gvm && go mod vendor
RUN --mount=type=ssh source /root/.gvm/scripts/gvm && go build -tags version -o jimmsrv -v -a -mod vendor ./cmd/jimmsrv
RUN go build -tags version -o jimmsrv -v ./cmd/jimmsrv

# Define a smaller single process image for deployment
FROM ${DOCKER_REGISTRY}ubuntu:20.04 AS deploy-env
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ PROJECT := github.com/canonical/jimm

GIT_COMMIT := $(shell git rev-parse --verify HEAD)
GIT_VERSION := $(shell git describe --abbrev=0 --dirty)
GO_VERSION := $(shell go list -f {{.GoVersion}} -m)

ifeq ($(shell uname -p | sed -r 's/.*(x86|armel|armhf).*/golang/'), golang)
GO_C := golang
Expand Down Expand Up @@ -84,6 +85,7 @@ jimm-image:
docker build --target deploy-env \
--build-arg="GIT_COMMIT=$(GIT_COMMIT)" \
--build-arg="VERSION=$(GIT_VERSION)" \
--build-arg="GO_VERSION=$(GO_VERSION)" \
--tag jimm:latest .

jimm-snap:
Expand Down
12 changes: 8 additions & 4 deletions internal/jimm/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,15 @@ func (j *JIMM) doCloudAdmin(ctx context.Context, u *dbmodel.User, ct names.Cloud
// an unauthorized error.
return errors.E(op, errors.CodeUnauthorized, "unauthorized")
}

if len(c.Regions) != 1 || len(c.Regions[0].Controllers) != 1 {
return errors.E(op, "cloud administration not available for %s", ct.Id())
// Ensure we always have at least 1 region for the cloud with at least 1 controller
// managing that region.
if len(c.Regions) < 1 || len(c.Regions[0].Controllers) < 1 {
zapctx.Error(ctx, "number of regions available in cloud", zap.String("cloud", c.Name), zap.Int("regions", len(c.Regions)))
if len(c.Regions) > 0 {
zapctx.Error(ctx, "number of controllers available for cloud/region", zap.Int("controllers", len(c.Regions[0].Controllers)))
}
return errors.E(op, fmt.Sprintf("cloud administration not available for %s", ct.Id()))
}

api, err := j.dial(ctx, &c.Regions[0].Controllers[0].Controller, names.ModelTag{})
if err != nil {
return errors.E(op, err)
Expand Down
15 changes: 15 additions & 0 deletions internal/jimm/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,7 @@ const grantCloudAccessTestEnv = `clouds:
host-cloud-region: test-cloud/test-cloud-region
regions:
- name: default
- name: region2
users:
- user: alice@external
access: admin
Expand All @@ -1141,6 +1142,9 @@ controllers:
- cloud: test
region: default
priority: 1
- cloud: test
region: region2
priority: 1
`

var grantCloudAccessTests = []struct {
Expand Down Expand Up @@ -1197,6 +1201,17 @@ var grantCloudAccessTests = []struct {
},
Priority: 1,
}},
}, {
Name: "region2",
Controllers: []dbmodel.CloudRegionControllerPriority{{
Controller: dbmodel.Controller{
Name: "controller-1",
UUID: "00000001-0000-0000-0000-000000000001",
CloudName: "test-cloud",
CloudRegion: "test-cloud-region",
},
Priority: 1,
}},
}},
Users: []dbmodel.UserCloudAccess{{
Username: "alice@external",
Expand Down

0 comments on commit e8b585d

Please sign in to comment.