Skip to content

Commit

Permalink
[release] v0.14.0-unstable21
Browse files Browse the repository at this point in the history
  • Loading branch information
azukaar committed Feb 8, 2024
1 parent 60fcbc1 commit 6aa0ffe
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 10 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Replaced network clean up by vanilla docker prune
- Fix issue with removing IP whitelist
- Add UI to create MCVlan networks
- Add a log file in config folder for the selfupdater
- Add a migration script to host mode
- UI optimizations (thanks @Kawanaao)
- Add duplicate filter on store listing
Expand Down
29 changes: 22 additions & 7 deletions client/src/pages/home/migrate014.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import {
MenuItem,
Grid,
FormHelperText,
CircularProgress,
} from '@mui/material';
import { ArrowRightOutlined, PlusCircleOutlined } from '@ant-design/icons';
import { LoadingButton } from '@mui/lab';
import * as API from '../../api';

const Migrate014 = ({ config }) => {
const [isOpened, setIsOpened] = useState(false);
const [isSubmitted, setIsSubmitted] = useState(false);
const [isSubmitted, setIsSubmitted] = useState(0);

const formik = useFormik({
initialValues: {
Expand All @@ -35,10 +36,13 @@ const Migrate014 = ({ config }) => {
https: Yup.number().required('HTTPS port is required').typeError('HTTPS port must be a number'),
}),
onSubmit: (values, { setErrors, setStatus, setSubmitting }) => {
setSubmitting(true);
return API.docker.migrateHost(values)
.then((res) => {
setIsSubmitted(true);
.then((res) => {
setSubmitting(true);
setIsSubmitted(1);
setTimeout(() => {
setIsSubmitted(2);
}, 15000);
setStatus({ success: true });
setSubmitting(false);
}).catch((err) => {
Expand All @@ -54,19 +58,29 @@ const Migrate014 = ({ config }) => {
<Dialog open={isOpened} onClose={() => setIsOpened(false)}>
<FormikProvider value={formik}>
<DialogTitle>Migrate to Host Mode</DialogTitle>
{isSubmitted ?
{isSubmitted ? ((isSubmitted == 2) ?
<DialogContent>
<DialogContentText>
Migration successful! Your Cosmos instance will now restart in Host Mode.
Refresh the page to see the changes (it might take a minute!).
Refresh the page to see the changes (it might take a few minutes!).
if you are experiencing issues, please check the logs for more information.
</DialogContentText>
</DialogContent>
:
<DialogContent>
<DialogContentText>
<center>
<CircularProgress
size={80}
/>
</center>
</DialogContentText>
</DialogContent>)
:
<DialogContent>
<DialogContentText>
In order to continue to improve your experience, Cosmos now supports the Host Mode of networking.
It will the recommended way to run your Cosmos container from now on. <strong>If you are using Windows do not do this, it's not compatible</strong> (you can disable this warning in the config file).
It will be the recommended way to run your Cosmos container from now on. <strong>If you are using Windows do not do this, it's not compatible</strong> (you can disable this warning in the config file).
<br />Example of how it makes your life easier:
<ul>
<li>You will be able to connect to other services using localhost</li>
Expand All @@ -78,6 +92,7 @@ const Migrate014 = ({ config }) => {
</ul>
Cosmos can automatically migrate to the host mode, but before you do so, please confirm what ports you want to use with Cosmos (default are 80/443).
The reason why we ask you to do this is that the host mode will use your server's network directly, not the docker virtual network. This means your port redirection (ex. -p 80:8080) will not be there anymore, and you need to tell Cosmos what ports to actually use directly. This form will save the settings for you and start the migration.
If you have very customized Cosmos networking settings (ex. macvlan), the auto migration will not work, and you will need to do it manually.
<br />
<br />
</DialogContentText>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cosmos-server",
"version": "0.14.0-unstable20",
"version": "0.14.0-unstable21",
"description": "",
"main": "test-server.js",
"bugs": {
Expand Down
1 change: 0 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<a href="https://github.com/DGAzr"><img src="https://avatars.githubusercontent.com/DGAzr" style="border-radius:48px" width="48" height="48" alt="null" title="null" /></a>
<a href="https://github.com/eldergod1800"><img src="https://avatars.githubusercontent.com/eldergod1800" style="border-radius:48px" width="48" height="48" alt="null" title="null" /></a>
<a href="https://github.com/Fortcraft"><img src="https://avatars.githubusercontent.com/Fortcraft" style="border-radius:48px" width="48" height="48" alt="null" title="null" /></a>
<a href="https://github.com/Quinnus"><img src="https://avatars.githubusercontent.com/Quinnus" style="border-radius:48px" width="48" height="48" alt="null" title="null" /></a>
</p><!-- /sponsors -->

---
Expand Down
6 changes: 5 additions & 1 deletion src/docker/checkPorts.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,18 @@ func UpdatePorts(finalPorts []string) error {
},
},
};



utils.Log("SelUpdatePorts - Creating updater service")
utils.Log("Creating self-updater service: docker run -d --name cosmos-self-updater-agent -e CONTAINER_NAME=" + containerName + " -e ACTION=ports -e DOCKER_HOST=" + os.Getenv("DOCKER_HOST") + " -e PORTS=" + strings.Join(finalPorts, ",") + " -v /var/run/docker.sock:/var/run/docker.sock azukaar/docker-self-updater:" + version)

err := CreateService(service, func (msg string) {})

if err != nil {
return err
}

go redirectLogs("cosmos-self-updater-agent", utils.CONFIGFOLDER + "/logs-cosmos-self-updater-agent.log")

return nil
}
31 changes: 31 additions & 0 deletions src/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,15 +667,46 @@ func SelfAction(action string) error {
},
};

utils.Log("Creating self-updater service: docker run -d --name cosmos-self-updater-agent -e CONTAINER_NAME=" + containerName + " -e ACTION=" + action + " -e DOCKER_HOST=" + os.Getenv("DOCKER_HOST") + " -v /var/run/docker.sock:/var/run/docker.sock azukaar/docker-self-updater:" + version)

err := CreateService(service, func (msg string) {})

if err != nil {
return err
}

// attach logs
go redirectLogs("cosmos-self-updater-agent", utils.CONFIGFOLDER + "/logs-cosmos-self-updater-agent.log")

return nil
}

func redirectLogs(containerName string, logFile string) {
// attach logs
logs, err := DockerClient.ContainerLogs(DockerContext, containerName, types.ContainerLogsOptions{
ShowStdout: true,
ShowStderr: true,
Follow: true,
})
if err != nil {
utils.Error("redirectLogs", err)
}

// replace file if exist
file, err := os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0770)
if err != nil {
utils.Error("redirectLogs", err)
}

defer file.Close()
defer logs.Close()

_, err = io.Copy(file, logs)
if err != nil {
utils.Error("redirectLogs", err)
}
}

func DockerPullImage(image string) (io.ReadCloser, error) {
utils.Debug("DockerPull - Preparing Pulling image " + image)

Expand Down

0 comments on commit 6aa0ffe

Please sign in to comment.