Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 解决容器镜像为空导致升级失败的问题 #3287

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions backend/app/service/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ func (u *ContainerService) ContainerInfo(req dto.OperationWithName) (*dto.Contai
}
}
data.AutoRemove = oldContainer.HostConfig.AutoRemove
data.Privileged = oldContainer.HostConfig.Privileged
data.PublishAllPorts = oldContainer.HostConfig.PublishAllPorts
data.RestartPolicy = oldContainer.HostConfig.RestartPolicy.Name
if oldContainer.HostConfig.NanoCPUs != 0 {
Expand Down Expand Up @@ -440,7 +441,7 @@ func (u *ContainerService) ContainerUpdate(req dto.ContainerOperate) error {
if !req.ForcePull {
return err
}
global.LOG.Errorf("force pull image %s failed, err: %v", req.Image, err)
return fmt.Errorf("pull image %s failed, err: %v", req.Image, err)
}
}

Expand Down Expand Up @@ -483,7 +484,7 @@ func (u *ContainerService) ContainerUpgrade(req dto.ContainerUpgrade) error {
if !req.ForcePull {
return err
}
global.LOG.Errorf("force pull image %s failed, err: %v", req.Image, err)
return fmt.Errorf("pull image %s failed, err: %v", req.Image, err)
}
}
config := oldContainer.Config
Expand Down
28 changes: 11 additions & 17 deletions backend/app/service/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,31 +485,20 @@ func (u *FirewallService) updatePingStatus(enable string) error {
if err != nil {
return err
}
hasV4Line, hasV6Line := false, false
if _, err := os.Stat("/proc/sys/net/ipv6/icmp_echo_ignore_all"); err != nil {
hasV6Line = true
}
files := strings.Split(string(lineBytes), "\n")
var newFiles []string
hasLine := false
for _, line := range files {
if strings.HasPrefix(strings.ReplaceAll(line, " ", ""), "net/ipv4/icmp_echo_ignore_all") && !hasV4Line {
if strings.Contains(line, "net/ipv4/icmp_echo_ignore_all") || strings.HasPrefix(line, "net/ipv4/icmp_echo_ignore_all") {
newFiles = append(newFiles, "net/ipv4/icmp_echo_ignore_all="+enable)
hasV4Line = true
continue
}
if strings.HasPrefix(strings.ReplaceAll(line, " ", ""), "net/ipv6/icmp_echo_ignore_all") && !hasV6Line {
newFiles = append(newFiles, "net/ipv6/icmp_echo_ignore_all="+enable)
hasV6Line = true
continue
hasLine = true
} else {
newFiles = append(newFiles, line)
}
newFiles = append(newFiles, line)
}
if !hasV4Line {
if !hasLine {
newFiles = append(newFiles, "net/ipv4/icmp_echo_ignore_all="+enable)
}
if !hasV6Line {
newFiles = append(newFiles, "net/ipv6/icmp_echo_ignore_all="+enable)
}
file, err := os.OpenFile(confPath, os.O_WRONLY|os.O_TRUNC, 0666)
if err != nil {
return err
Expand All @@ -526,6 +515,11 @@ func (u *FirewallService) updatePingStatus(enable string) error {
if err != nil {
return fmt.Errorf("update ping status failed, err: %v", stdout)
}
handle := "-A"
if enable == "1" {
handle = "-D"
}
_, _ = cmd.Execf("%s ip6tables %s INPUT -p icmpv6 --icmpv6-type echo-request -j DROP", cmd.SudoHandleCmd(), handle)

return nil
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lang/modules/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ const message = {
'The upgrade operation requires rebuilding the container, and any non-persistent data will be lost. Do you want to continue?',
oldImage: 'Current image',
targetImage: 'Target image',
targetImageHelper: 'Please enter the target image version',
imageLoadErr: 'System did not detect the container image name, please manually enter the full image name:tag ',
appHelper:
'This container is sourced from the application store. Upgrading it may cause the service to be unavailable.',

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lang/modules/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ const message = {
upgradeWarning2: '升級操作需要重建容器,任何未持久化的數據將會丟失,是否繼續?',
oldImage: '當前鏡像',
targetImage: '目標鏡像',
targetImageHelper: '請輸入目標鏡像版本',
imageLoadErr: '系統未檢測到容器的鏡像名稱,請手動輸入完整的鏡像名稱:標籤',
appHelper: '該容器來源於應用商店,升級可能導致該服務不可用',

input: '手動輸入',
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lang/modules/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ const message = {
upgradeWarning2: '升级操作需要重建容器,任何未持久化的数据将会丢失,是否继续?',
oldImage: '当前镜像',
targetImage: '目标镜像',
targetImageHelper: '请输入目标镜像版本',
imageLoadErr: '系统未检测到容器的镜像名称,请手动输入完整的镜像名称:标签',
appHelper: '该容器来源于应用商店,升级可能导致该服务不可用',

input: '手动输入',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/views/container/compose/create/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ const acceptParams = (): void => {
form.path = '';
form.file = '';
form.template = null;
onCreating.value = false;
loadTemplates();
loadPath();
};
Expand Down
59 changes: 39 additions & 20 deletions frontend/src/views/container/container/upgrade/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,33 @@
/>
<el-form @submit.prevent ref="formRef" :model="form" label-position="top">
<el-form-item :label="$t('container.oldImage')" prop="oldImage">
<el-tooltip placement="top-start" :content="form.imageName" v-if="form.imageName.length > 50">
<el-tag>{{ form.imageName.substring(0, 50) }}...:{{ form.oldTag }}</el-tag>
<el-tooltip
placement="top-start"
:content="form.oldImageName"
v-if="form.oldImageName.length > 50"
>
<el-tag>{{ form.oldImageName.substring(0, 50) }}...</el-tag>
</el-tooltip>
<el-tag v-else>{{ form.imageName }}:{{ form.oldTag }}</el-tag>
<el-tag v-else>{{ form.oldImageName }}</el-tag>
</el-form-item>
<el-form-item prop="newTag" :rules="Rules.imageName">
<el-form-item prop="newImageName" :rules="Rules.imageName">
<template #label>
<el-tooltip
placement="top-start"
:content="form.imageName"
v-if="form.imageName.length > 40"
:content="form.imageHelper"
v-if="form.imageHelper.length > 40"
>
<span>
{{ $t('container.targetImage') + ' (' + form.imageName.substring(0, 40) + '...)' }}
{{
$t('container.targetImage') + ' (' + form.imageHelper.substring(0, 40) + '...)'
}}
</span>
</el-tooltip>
<span v-else>
{{ $t('container.targetImage') + ' (' + form.imageName + ')' }}
{{ $t('container.targetImage') + ' (' + form.imageHelper + ')' }}
</span>
</template>
<el-input v-model="form.newTag" :placeholder="$t('container.targetImageHelper')" />
<el-input v-model="form.newImageName" :placeholder="$t('container.imageNameHelper')" />
<span class="input-help">{{ $t('container.upgradeHelper') }}</span>
</el-form-item>
<el-form-item prop="ignoreCompare">
Expand Down Expand Up @@ -79,9 +85,9 @@ const loading = ref(false);

const form = reactive({
name: '',
imageName: '',
oldTag: '',
newTag: '',
oldImageName: '',
newImageName: '',
imageHelper: '',
fromApp: false,
forcePull: false,

Expand All @@ -100,11 +106,16 @@ interface DialogProps {
}
const acceptParams = (props: DialogProps): void => {
form.name = props.container;
form.imageName = props.image.indexOf(':') !== -1 ? props.image.split(':')[0] : props.image;
form.oldTag = props.image.indexOf(':') !== -1 ? props.image.split(':')[1] : 'latest';
form.newTag = form.oldTag;
form.oldImageName = props.image;
form.fromApp = props.fromApp;
form.ignoreCompare = false;

if (props.image.indexOf('sha256:') !== -1) {
form.imageHelper = i18n.global.t('container.imageLoadErr');
drawerVisible.value = true;
return;
}
form.imageHelper = props.image.indexOf(':') !== -1 ? props.image.split(':')[0] : props.image;
drawerVisible.value = true;
};
const emit = defineEmits<{ (e: 'search'): void }>();
Expand All @@ -113,7 +124,7 @@ const onSubmit = async (formEl: FormInstance | undefined) => {
if (!formEl) return;
formEl.validate(async (valid) => {
if (!valid) return;
if (!form.ignoreCompare && !compareVersion(form.newTag, form.oldTag)) {
if (!form.ignoreCompare && !compareVersion(form.newImageName, form.oldImageName)) {
MsgWarning(i18n.global.t('container.upgradeWarning'));
return;
}
Expand All @@ -122,7 +133,7 @@ const onSubmit = async (formEl: FormInstance | undefined) => {
cancelButtonText: i18n.global.t('commons.button.cancel'),
}).then(async () => {
loading.value = true;
await upgradeContainer(form.name, form.imageName + ':' + form.newTag, form.forcePull)
await upgradeContainer(form.name, form.newImageName, form.forcePull)
.then(() => {
loading.value = false;
emit('search');
Expand All @@ -141,14 +152,22 @@ const handleClose = async () => {
};

function compareVersion(vNew, vOld) {
if (vNew === 'latest') {
let newImageName = vNew.indexOf(':') !== -1 ? vNew.split(':')[0] : vNew;
let oldImageName = vOld.indexOf(':') !== -1 ? vOld.split(':')[0] : vOld;
if (newImageName !== oldImageName) {
return true;
}
let newTag = vNew.indexOf(':') !== -1 ? vNew.split(':')[1] : 'latest';

if (newTag === 'latest') {
return true;
}
let v1 = vNew
let oldTag = vOld.indexOf(':') !== -1 ? vOld.split(':')[1] : 'latest';
let v1 = newTag
.replace('-', '.')
.replace(/[^\d.]/g, '')
.split('.');
let v2 = vOld
let v2 = oldTag
.replace('-', '.')
.replace(/[^\d.]/g, '')
.split('.');
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/container/network/create/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ const handleClose = () => {
const rules = reactive({
name: [Rules.requiredInput],
driver: [Rules.requiredSelect],
subnet: [{ validator: checkCidr, trigger: 'blur' }],
subnet: [{ validator: checkCidr, trigger: 'blur' }, Rules.requiredInput],
gateway: [{ validator: checkGateway, trigger: 'blur' }],
scope: [{ validator: checkCidr, trigger: 'blur' }],
subnetV6: [{ validator: checkFixedCidrV6, trigger: 'blur' }],
subnetV6: [{ validator: checkFixedCidrV6, trigger: 'blur' }, Rules.requiredInput],
gatewayV6: [{ validator: checkGatewayV6, trigger: 'blur' }],
scopeV6: [{ validator: checkFixedCidrV6, trigger: 'blur' }],
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/toolbox/fail2ban/ips/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<el-drawer :close-on-click-modal="false" v-model="drawerVisible" size="30%">
<el-drawer :close-on-click-modal="false" :destroy-on-close="true" v-model="drawerVisible" size="30%">
<template #header>
<Header :header="$t('toolbox.fail2ban.' + form.operate + 'IP')" :back="handleClose"></Header>
</template>
Expand Down
Loading