-
Notifications
You must be signed in to change notification settings - Fork 3
update rust-webservice template to use build container #44
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,4 @@ def index(): | |
</form> | ||
</body> | ||
</html> | ||
""" | ||
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
zer0x64 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# This Ansible script is used to compile your challenge, create an archive and extract that archive on to the local host. | ||
# This script builds a frontend using NPM and a Rust program. Change it as per your needs. | ||
- name: "Build container" | ||
hosts: "build-container" | ||
vars_files: | ||
- ../track.yaml | ||
tasks: | ||
- name: "Load flags" | ||
loop: "{{ '{{ flags }}' }}" | ||
vars: | ||
key: "{{ '{{ (item.tags).discourse }}' }}" | ||
value: "{{ '{{ item.flag }}' }}" | ||
ansible.builtin.set_fact: | ||
track_flags: "{{ '{{ track_flags | default({}) | combine({key: value}) }}' }}" | ||
|
||
- name: Check if IPv4 address is set | ||
ansible.builtin.debug: | ||
msg: IPv4 address is set | ||
when: ansible_all_ipv4_addresses | length > 0 | ||
|
||
- name: Initial System Upgrade | ||
ansible.builtin.apt: | ||
update_cache: true | ||
install_recommends: false | ||
upgrade: full | ||
|
||
# Install the tools required to compile your code such as npm, nodejs, gcc... | ||
- name: Install dependencies to build the track | ||
ansible.builtin.apt: | ||
name: | ||
- npm | ||
- curl | ||
state: present | ||
|
||
- name: Check if cargo is installed | ||
ansible.builtin.stat: | ||
path: /root/.cargo/bin/cargo | ||
register: cargo_exists | ||
|
||
- name: Download Cargo Installer | ||
ansible.builtin.get_url: | ||
url: https://sh.rustup.rs | ||
dest: /tmp/sh.rustup.rs | ||
mode: '0755' | ||
force: true | ||
when: not cargo_exists.stat.exists | ||
tags: | ||
- rust | ||
|
||
- name: Install Cargo | ||
when: not cargo_exists.stat.exists | ||
ansible.builtin.command: /tmp/sh.rustup.rs -y | ||
register: my_output | ||
changed_when: my_output.rc != 0 | ||
tags: | ||
- rust | ||
|
||
- name: Copy the challenge sources | ||
ansible.builtin.copy: | ||
src: challenge/ | ||
dest: /tmp/{{ data.name }} | ||
owner: root | ||
group: root | ||
mode: '0644' | ||
|
||
- name: NPM install (if IPv4) | ||
community.general.npm: | ||
path: /tmp/{{ data.name }}/client/ | ||
environment: | ||
NODE_OPTIONS: "--dns-result-order=ipv4first" | ||
when: ansible_all_ipv4_addresses | length > 0 | ||
|
||
- name: NPM install (if IPv6) | ||
community.general.npm: | ||
path: /tmp/{{ data.name }}/client/ | ||
when: ansible_all_ipv4_addresses | length == 0 | ||
|
||
- name: Build | ||
ansible.builtin.command: | ||
cmd: /root/.cargo/bin/cargo build --release | ||
chdir: /tmp/{{ data.name }}/ | ||
register: my_output | ||
changed_when: my_output.rc != 0 | ||
|
||
- name: Create dist directory | ||
ansible.builtin.file: | ||
path: /tmp/dist/{{ data.name }} | ||
state: directory | ||
mode: '0755' | ||
|
||
- name: Copy server binary | ||
ansible.builtin.copy: | ||
remote_src: true | ||
src: /tmp/{{ data.name }}/target/release/{{ data.name }} | ||
dest: /tmp/dist/{{ data.name }}/{{ data.name }} | ||
owner: root | ||
group: root | ||
mode: '0744' | ||
|
||
- name: Copy client | ||
ansible.builtin.copy: | ||
remote_src: true | ||
src: /tmp/{{ data.name }}/dist | ||
dest: /tmp/dist/{{ data.name }}/ | ||
owner: root | ||
group: root | ||
mode: '0644' | ||
|
||
# Create a TAR archive with the compiled program | ||
- name: Create archive of build | ||
community.general.archive: | ||
path: /tmp/dist/{{ data.name }} | ||
dest: /tmp/build.tar | ||
format: tar | ||
mode: '0644' | ||
|
||
# Extract the archive from the build container and save it on the local host | ||
- name: Fetch archive | ||
ansible.builtin.fetch: | ||
src: /tmp/build.tar | ||
dest: /tmp/nsec/{{ data.name }}.tar | ||
flat: true |
MOBergeron marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this could be simplified by assuming true if a build.yaml.j2 file is present in the template dir. However it can be a bit awkward to check with the current codebase