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

add custom docker image suport #166

Merged
merged 2 commits into from
Sep 11, 2018
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
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,29 +71,29 @@ Enable syntax highlighting by add `files.associations` configuration in `setting

#### Run Playbook in Docker
1. Make sure Docker is installed and running. For non-Windows platform, please configure Docker run without sudo.
1. Default docker image is [microsoft/ansible:latest](https://hub.docker.com/r/microsoft/ansible/tags/), which is latest Ansible version. Customizing your own docker image/command by configuration `ansible.termininalInitCommand`, eg. `docker run -i -t microsoft/ansible:ansible2.5.5 /bin/bash`.
1. Default docker image is [microsoft/ansible:latest](https://hub.docker.com/r/microsoft/ansible/tags/), which is latest Ansible version. Customizing your own docker image by configuration item `ansible.dockerImage`, customizing docker init command by configuration `ansible.termininalInitCommand`, eg. `docker run -i -t microsoft/ansible:ansible2.5.5 /bin/bash`. Detail please see [configuration](#configuration).
1. For Windows user, please share your Windows driver where vscode workspace sits on with docker. This is because the extension will map your workspace containing playbook with docker.
![docker share driver](./images/dockerconfig.png)
1. This step is optional. If you want to run cloud provider specific Ansible modules, you need set cloud credentials in credential yaml file, default path is `$HOME/.vscode/ansible-credentials.yml`, or change credential file path by settings item `ansible.credentialsFile`. Credential file template is at [here](https://github.com/VSChina/vscode-ansible/blob/master/config/credentials.yml).
1. Press `F1`, type: `ansible`, choose `Run Ansible Playbook in Docker`. Or right click playbook yaml file, choose `Run Ansible Playbook in Docker`.


***NOTE***
- Docker on Windows is not as stable as on other platforms, please try to restart Docker in case of any issue.
- Downloading Docker image first time usage may be time consuming in case of slow network connection.

#### Run Playbook in Local Ansible
1. Make sure Ansible is installed.
1. This step is optional. If you want to run cloud provider specific Ansible modules, please setup cloud credentials by following [Ansible instruction](http://docs.ansible.com/ansible/latest/guides.html). Or you can set cloud credentials in credential yaml file, default path is `$HOME/.vscode/ansible-credentials.yml`, or change credential file path by settings item `ansible.credentialsFile`. Credential file template is at [here](https://github.com/VSChina/vscode-ansible/blob/master/config/credentials.yml).
1. Press `F1`, type: `ansible`, choose `Run Ansible Playbook in Local Ansible`. Or right click playbook yaml file, choose `Run Ansible Playbook in Local Ansible`.
1. This step is optional. If you want to run cloud provider specific Ansible modules, please setup cloud credentials by following [Ansible instruction](http://docs.ansible.com/ansible/latest/guides.html). Or you can set cloud credentials in credential file, default path is `$HOME/.vscode/ansible-credentials.yml`, change credential file path by settings item `ansible.credentialsFile`. Credential file template is at [here](https://github.com/VSChina/vscode-ansible/blob/master/config/credentials.yml).
1. Press `F1`, type: `Ansible`, choose `Run Ansible Playbook in Local Ansible`. Or right click playbook yaml file, choose `Run Ansible Playbook in Local Ansible`.



#### Run Playbook in Cloud Shell
1. **Important** Please setup Cloud Shell for first time usage in Azure Portal by following [this instruction](https://docs.microsoft.com/en-us/azure/cloud-shell/overview). After setup, input cmd `az account show` to learn your current subscription setting.
1. Install [Azure Account](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account) VSCode extension, which is used for Azure login.
1. Press `F1`, type: `Azure: Sign In`, do Azure login.
1. Press `F1`, type: `ansible`, choose `Run Ansible Playbook in Cloud Shell`. Or right click playbook yaml file, choose `Run Ansible Playbook in Cloud Shell`.
1. Press `F1`, type: `Ansible`, choose `Run Ansible Playbook in Cloud Shell`. Or right click playbook yaml file, choose `Run Ansible Playbook in Cloud Shell`.
1. Confirm awareness on Azure usage fee. Please refer to [this document](https://docs.microsoft.com/en-us/azure/cloud-shell/pricing) to learn more about Azure Cloud Shell pricing.
1. **Known issue** due to [adal issue](https://github.com/AzureAD/azure-activedirectory-library-for-nodejs/issues/197), introduced in [azure account](https://github.com/Microsoft/vscode-azure-account/issues/53) extension, user might see `Entry not found` error when connect to cloud shell. Please retry open cloud shell.

Expand All @@ -106,7 +106,8 @@ Enable syntax highlighting by add `files.associations` configuration in `setting
"port": 22,
"user": "your user name",
"password": "your ssh password",
"key": "your private key"
"key": "your private key",
"passphrase": "your passphrase"
}
]
```
Expand Down Expand Up @@ -135,8 +136,10 @@ This extension provides below configurations in settings.json.
|`ansible.autocompletion` | `true` | Enable/Disable ansible autocompletion(including code snippets) functionality. To enable ansible autocompletion only in specific yaml files, set `ansible.autocompletion = false`, then add `# ansible-configured` header in first line of yaml file.|
|`ansible.credentialsFile` |`$HOME/.vscode/ansible-credentials.yml` |Specify ansible credentials file path, used when run playbook in Docker/Local Ansible. |
|`ansible.termininalInitCommand`|Default is `docker run` command for Docker, and `ansible-playbook` for local ansible.| Specify customized terminal init command when run playbook in Docker/Local Ansible. |
|`ansible.dockerImage`|`microsoft/ansible:latest`|Docker image name when running playbook in Docker.|
|`ansible.reuseSSHTerminal`|`true`| Enable/Disable SSH terminal reusing. |
|`ansible.customOptions`| null | Customize run playbook options. eg. `-i xxxx -vvv`.|
|`ansible.fileCopyConfig`| null | File copying configuration when running playbook remotely via SSH. It's array of configuration. Please see detail at [above](files-copy-to-remote-on-saving)|


## Feedback and Questions
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@
"type": "array",
"default": "",
"description": "Config file copying to remote host, including weather copy file on save. E.g. [ { \"server\": \"host\", \"sourcePath\":\"/mypath/\", \"targetPath\": \"/destpath/\", \"copyOnSave\", \"true\" }]"
},
"ansible.dockerImage": {
"type": "string",
"default": "microsoft/ansible:latest",
"description": "Custom docker image when running playbook in Docker."
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class Constants {
public static Config_cloudShellConfirmed = 'cloudShellConfirmed';
public static Config_credentialConfigured = 'credentialsConfigured';
public static Config_credentialsFile = 'credentialsFile';
public static Config_dockerImage = 'dockerImage';
public static Config_terminalInitCommand = 'terminalInitCommand';
public static GitHubApiHost = 'api.github.com';
public static GitHubRawContentHost = 'raw.githubusercontent.com';
Expand Down
10 changes: 9 additions & 1 deletion src/dockerRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class DockerRunner extends TerminalBaseRunner {
cmd += ' -e ' + Constants.UserAgentName + '=' + utilities.getUserAgent() + ' ';
}

cmd += ' ' + Constants.DockerImageName + ' bash';
cmd += ' ' + this.getDockerImageName() + ' bash';
cmdsToTerminal.push(cmd);
cmdsToTerminal.push(this.getRunPlaybookCmd(targetPlaybook));
} else {
Expand Down Expand Up @@ -127,4 +127,12 @@ export class DockerRunner extends TerminalBaseRunner {
}
});
}

private getDockerImageName(): string {
let customDocker = utilities.getCodeConfiguration<string>('ansible', Constants.Config_dockerImage);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to write the code as let customDocker = utilities.getCodeConfiguration<string>('ansible', Constants.Config_dockerImage) || Constants.DockerImageName;

if (!customDocker) {
customDocker = Constants.DockerImageName;
}
return customDocker;
}
}