1
0
forked from ovh/pci-test

Compare commits

...

10 Commits

Author SHA1 Message Date
syrell
fac76a23ea fix: Use entrypoint instead of cmd in Dockerfile 2024-12-03 15:57:45 +01:00
syrell
a3da5e0425 feat: Added exercise 3 and .gitignore 2024-12-03 15:50:29 +01:00
syrell
6ef29fd620 feat: Added exercise 1 and 2 2024-12-01 21:31:29 +01:00
syrell
9af118a396 feat: Added exercise 4 2024-12-01 21:26:38 +01:00
9ef89a992f Replace with placeholder
Signed-off-by: Arnaud Morin <arnaud.morin@ovhcloud.com>
2024-11-20 16:25:30 +01:00
a1ab1f4dcc Add info about forking
Signed-off-by: Arnaud Morin <arnaud.morin@ovhcloud.com>
2024-10-25 23:57:34 +02:00
Charles Vaillancourt
aec71aa51a Added some more python exercises 2024-10-25 23:50:25 +02:00
Florent Le Lain
0b0ab94faa add app binary 2024-10-25 23:50:25 +02:00
Florent Le Lain
0418052330 update README file 2024-10-25 23:50:25 +02:00
Arnaud Morin
a8f341a85f Add readme
Signed-off-by: Arnaud Morin <arnaud.morin@gmail.com>
2024-10-25 23:50:25 +02:00
17 changed files with 334 additions and 1 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*/__pycache__
**/.terraform/*
**/*.tfstate
**/*.tfstate.*

174
README.md
View File

@ -1 +1,173 @@
# merge-vs-rebase
# Intro
We created this set of exercises to give you the opportunity to express yourself technically. Do as much as you can in
the time you have. Feel free to ask us questions, if any. No worries if you can't make it all by lack of time or
understanding of what we're asking. We'll defrief it with you during our next call.
**Have fun!**
## Fork
Register an account and fork this repo.
You will push your results to your fork.
# Ex. 1 - python
This exercise will be split into multiple smaller ones. For each one
you can create files named `a.py`, `b.py` and `c.py`. You maybe resuse the same
environment for all sub-exercises
Guidelines:
- Use python version python3.7+.
- Unless specified otherwise you can only use builtin modules.
### python - A
Write a script that prints out whatever text input is passed as argument
Example:
```
$ python a.py ping ping ping
ping ping ping
```
### python - B
Write a script take takes one argument (-t/--target) which can only
accept the following values `titi`, `toto`, `tata`. When called with a valid
target, the script should print out the target text to stdout (`titi`, `toto` or `tata`).
When an invalid target is provided an error message should be printed to stderr
Example:
```
$ python b.py --target titi
titi
$ python b.py -t tutu
usage: b.py [-h] [-t {titi,toto,tata}]
b.py: error: argument -t/--target: invalid choice: 'tutu' (choose from 'titi', 'toto', 'tata')
```
### python - C
Write a script that creates ascii art equivalent of text passed as argument.
For this exercise you may use a 3rd party module.
Example:
```bash
$ python c.py 'Hello buddies'
_ _ _ _ _ _ _ _
| | | | ___ | || | ___ | |__ _ _ __| | __| |(_) ___ ___
| |_| | / _ \| || | / _ \ | '_ \ | | | | / _` | / _` || | / _ \/ __|
| _ || __/| || || (_) | | |_) || |_| || (_| || (_| || || __/\__ \
|_| |_| \___||_||_| \___/ |_.__/ \__,_| \__,_| \__,_||_| \___||___/
```
# Ex. 2 - docker
In ex2 folder, you will find a `app` binary.
Can you build very lighweight docker image that contains ONLY `app` binary, and that execute `app` by default?
Push your Dockerfile in the ex2 folder.
# Ex. 3 - terraform
In ex3 folder, you will find an incomplete `openrc` file.
You will need to amend the file to configure the correct `OS_USERNAME`, `OS_PASSWORD` and `OS_REGION_NAME` with the one that we gave to you.
Then, using `terraform`, can you write a plan to boot a `d2-4` with a floating IP.
Bonus, on that instance, make sure a web server (`nginx`) is running.
Push your `main.tf` file in ex3 folder.
# Ex. 4 - git
In this repo, there are two branches:
- stein
- queens
Stein contains the following commits:
- 1ff2641 (stein) G
- cf24853 F
- 3fcdfa0 E
- cb8c71a D
- 849ef26 C
- 372c155 B
- edc8ed7 A
Queens contains the following commits:
- 2624c16 (queens) F
- 5e3521b B
- edc8ed7 A
So the common ancestor is A (same commit ID).
B has been cherry-picked from stein to queens, without conflicts.
F has also been cherry-picked but with conflicts (solved, of course).
## Exercice
You will need to create two branches:
- merged
- rebased
### Merged
Create the merged branch first:
```bash
git checkout -b merged origin/queens
```
Then merge the stein branch into your branch
```bash
git merge origin/stein
```
You will have a conflict to solved.
Solve it, then push your `merged` branch to your repo.
### Rebased
Now create the rebased branch:
```bash
git checkout -b rebased origin/queens
```
Now rebase it on top of stein:
```bash
git rebase -i origin/stein
```
You will have a conflict to solved.
Solve it, then push your `rebased` branch to your repo.
## Check diff
Now check the diff between your two branches `merged` and `rebased`.
```bash
git diff merged..rebased
```
Can you explain why you have a diff?
Write down the explanation in ex4 folder (like in a `README.md` file)

0
ex1/.placeholder Normal file
View File

9
ex1/a.py Normal file
View File

@ -0,0 +1,9 @@
import sys
def print_args():
return " ".join(sys.argv[1:])
if __name__ == "__main__":
print(print_args())

13
ex1/b.py Normal file
View File

@ -0,0 +1,13 @@
import argparse
import sys
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-t", "--target", choices=["titi", "toto", "tata"])
args = parser.parse_args()
return args.target
if __name__ == "__main__":
print(main())

10
ex1/c.py Normal file
View File

@ -0,0 +1,10 @@
from a import print_args
from art import text2art
def main():
return text2art(print_args())
if __name__ == "__main__":
print(main())

0
ex2/.placeholder Normal file
View File

3
ex2/Dockerfile Normal file
View File

@ -0,0 +1,3 @@
FROM scratch
COPY app /
ENTRYPOINT ["/app"]

BIN
ex2/app Executable file

Binary file not shown.

0
ex3/.placeholder Normal file
View File

23
ex3/.terraform.lock.hcl Normal file
View File

@ -0,0 +1,23 @@
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/terraform-provider-openstack/openstack" {
version = "1.42.0"
constraints = "~> 1.42.0"
hashes = [
"h1:hpQ+kc+S2Nwcqqt0TtBdiLKJpaLxq5z2eKrA+kjoMq4=",
"zh:116e297f03eb304819f8cffd66f25b77638435db2d612c2b1d56205cbbef485f",
"zh:332411f8425caaa9ca799cc60ccbab188c6108fa2765032a5cb22a5df36b5fc5",
"zh:3843cf3c563ae0348bcd41107508399df997a7293b2a3a79e73264be81dc456c",
"zh:4d16af37327d36bb86913220b763ed6e599b47db7702948f019e535c5b9413d4",
"zh:9557b325e4617977f0fec913673d2542556174811415417be7dee20f7ab2fec1",
"zh:95b4754370eda28624f7dfcfdfc4016775bf6433535b60a8f3d99fd651e71afa",
"zh:97c240eba6a179e5910c0afdee97f916ab4537b360db21143ab2dfb0919087e3",
"zh:b231c1c988914f4f0be3115a432f50cf43c410867f8b3aff7e3bf7c31739c940",
"zh:b3b105ee70e440d350d8fecf50d458ad7d4b9b4a3ab580e9b8ff1e3fec9a6b76",
"zh:b531f02dca64486c302046d959770a6b32ac26fc6d1830582e9959d0384dbe20",
"zh:b80a2e60dae300217f44318a74b7e45cfe7009a11b937f06fb07f677863cec59",
"zh:f18e8dada1e2941585893c579d169bc908c68cb7b71406c47cafc0a3bdcddbe8",
"zh:fbdc031f496fa1f80fcab41f1e3cf2e2f99b0266b685079b4a4c4c61720c914c",
]
}

58
ex3/main.tf Normal file
View File

@ -0,0 +1,58 @@
resource "openstack_networking_router_v2" "rt" {
name = "rt"
admin_state_up = "true"
external_network_id = var.network_external_id
}
resource "openstack_networking_network_v2" "network_internal" {
name = var.network_lan
admin_state_up = "true"
}
resource "openstack_networking_subnet_v2" "network_subnet" {
name = var.network_lan
network_id = openstack_networking_network_v2.network_internal.id
cidr = var.network_subnet_cidr
ip_version = 4
enable_dhcp = true
dns_nameservers = ["1.1.1.1"]
}
resource "openstack_networking_router_interface_v2" "network_router_interface" {
router_id = openstack_networking_router_v2.rt.id
subnet_id = openstack_networking_subnet_v2.network_subnet.id
}
resource "openstack_networking_floatingip_v2" "d2_fip" {
pool = "Ext-Net"
}
resource "openstack_compute_keypair_v2" "instance_keypair" {
provider = openstack.ovh
name = "instance_keypair"
public_key = file(var.ssh_pubkey)
}
resource "openstack_compute_instance_v2" "instance" {
name = "d2_test"
provider = openstack.ovh
image_name = "Debian 12"
flavor_name = "d2-4"
key_pair = openstack_compute_keypair_v2.instance_keypair.name
user_data = var.cloudinit_script
network {
name = var.network_lan
}
depends_on = [ openstack_networking_subnet_v2.network_subnet ]
}
data "openstack_networking_port_v2" "port" {
device_id = openstack_compute_instance_v2.instance.id
network_id = openstack_compute_instance_v2.instance.network.0.uuid
}
resource "openstack_networking_floatingip_associate_v2" "fip_associate" {
floating_ip = openstack_networking_floatingip_v2.d2_fip.address
port_id = data.openstack_networking_port_v2.port.id
}

1
ex3/openrc Normal file
View File

@ -0,0 +1 @@
# Placeholder

13
ex3/providers.tf Normal file
View File

@ -0,0 +1,13 @@
terraform {
required_version = ">= 0.14.0"
required_providers {
openstack = {
source = "terraform-provider-openstack/openstack"
version = "~> 1.42.0"
}
}
}
provider "openstack" {
alias = "ovh"
}

24
ex3/variables.tf Normal file
View File

@ -0,0 +1,24 @@
variable "network_external_id" {
type = string
default = "bcf59eb2-9d83-41cc-b4f5-0435ed594833"
}
variable "network_lan" {
type = string
default = "lan_d2_demo"
}
variable "network_subnet_cidr" {
type = string
default = "10.10.0.0/24"
}
variable "ssh_pubkey" {
type = string
default = "~/.ssh/id_ed25519.pub"
}
variable "cloudinit_script" {
type = string
default = "#!/bin/bash\nsudo apt update && sudo apt install -y nginx"
}

0
ex4/.placeholder Normal file
View File

3
ex4/README.md Normal file
View File

@ -0,0 +1,3 @@
# Check diff
We have a diff between merged and rebased branches because merge and rebase are two different process that will not necessarily end in the same result. With merge we retrieve the remote branch at current stage (HEAD points to latest commit from the remote branch) so we will end up with exactly the same code than on the remote branch. With checkout we retrieve all commits we don't have from remote branch onto the common ancestor and other commits from our local branch are put after. In our case, our local branch was A => B => F so afer the merge we end up with A => B => F => merge commit wheareas after the rebase we end up with A => B => C => D => E => F => G => B" => F" since the common ancestor is A. Although B and F from our local branch were cherry-picked from stein branch applying them on top of stein commits (A => B => C => D => E => F => G) made new changes. More precisely, some hunks modified by B are overriden by new commits from stein branch (C, D, E or G) therefore since the rebase process reapplied the B commit these hunks have been modified once more hence the diff we have between merged and rebased branches. Finally, hunks modified by F were not overriden by G thus reapplying F didn't make any new change that's why rebased branch git tree is A => B => C => D => E => F => G => B".