Rule 1. Build your aerobic base.
You need to be able to ride at least the same distance of the route of your event, comfortably, keeping your HR in the aerobic zone. What is your aerobic zone? It is between 65% and 80% of your Max HR. If you don’t know how to calculate or assess your max HR read here.
Rule 2. After you have a base, start training on a specific terrain similar to the one of the event.
You always need to “simulate” your event while training.
Look at the profile (altimetria) of your event. Look if it has several hills, how many they are, how long they are and how steep they are. In addition, for longer and steeper climbs, look carefully for how long the steepest part is and where it occurs in the climb.
Rule 3. Train “progressively”.
If you are not trained to climb for 8 km at those grades, start with a shorter and/or less steep hill and progressively add length and/or grade each week. Start, for example, with a 4 km long hill with 4-5% grade and then every 1-2 weeks climb for longer or climb more than one hill and then progressively climb steeper hills.
If you do note have a hill as long try hill repetitions on the same one.
If you do not have a hill as steep, use harder gear ratio on the one available.
If you do not have hills at all use indoor power bikes. They have awesome inventory of different routes and climbs to simulate indoor.
Rule 4. Do not combine in the same training ride distance with intensity or specific hills training.
Include hills in your long distance ride, but climb them at low-medium intensity and avoid too steep or long climbs.
Keep the rides that are focus on specific training for specific terrain, shorter.